[jboss-user] [JBoss Seam] - Re: Seam remoting -- any plans for FacesContext support?

andrew.rw.robinson do-not-reply at jboss.com
Tue Sep 26 17:03:03 EDT 2006


Okay, I got this to work. I just needed to do a bit of simple OO programming.

1) Extend your servlet and overwrite the "Execute" path handler:
public class SeamRemotingServletEx
  |   extends SeamRemotingServlet
  | {
  |   private static final String REQUEST_PATH_EXECUTE = "/execute";
  | 
  |   /**
  |    * @see org.jboss.seam.remoting.SeamRemotingServlet#init(javax.servlet.ServletConfig)
  |    */
  |   @Override
  |   public void init(ServletConfig config)
  |     throws ServletException
  |   {
  |     super.init(config);
  |     RequestHandlerFactory.getInstance().registerHandler(REQUEST_PATH_EXECUTE, 
  |       new FacesExecutionHandler());
  |   }
  | }

2) Write the new handler with faces context support:
public class FacesExecutionHandler
  |   extends ExecutionHandler
  | {
  |   private ServletContext servletContext;
  |   
  |   /**
  |    * @see org.jboss.seam.remoting.InterfaceGenerator#setServletContext(javax.servlet.ServletContext)
  |    */
  |   @Override
  |   public void setServletContext(ServletContext ctx)
  |   {
  |     this.servletContext = ctx;
  |     super.setServletContext(ctx);
  |   }
  |   
  |   /**
  |    * @see org.jboss.seam.remoting.InterfaceGenerator#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  |    */
  |   @Override
  |   public void handle(HttpServletRequest request, HttpServletResponse response)
  |     throws Exception
  |   {
  |     getFacesContext(request, response);
  |     super.handle(request, response);
  |   }
  |   
  |   protected FacesContext getFacesContext(HttpServletRequest request,
  |     HttpServletResponse response)
  |   {
  |     FacesContext facesContext = FacesContext.getCurrentInstance();
  | 
  |     if (facesContext == null)
  |     {
  |       FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder
  |         .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
  |       LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder
  |         .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
  |       Lifecycle lifecycle = lifecycleFactory
  |         .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
  |       
  |       facesContext = contextFactory.getFacesContext(servletContext, request,
  |         response, lifecycle);
  |     }
  |     return facesContext;
  |   }
  | }

3) register the extended servlet instead of the Seam servlet. Follow all other configuration instruction verbatim.

And that is all she wrote. Now Seam remoting works perfectly fine with JSF. Remoting methods can have full access to JSF scoped beans, access the session through the external context, have "facesContext" be injectable, etc.

Perhaps a flag in some configuration file, or in the JavaScript to enable this? (or on the @WebRemote annotation?)

Thanks,
Andrew



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3974356#3974356

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3974356



More information about the jboss-user mailing list