This content has been marked as final.
Show 2 replies
-
1. Re: Seam remoting -- any plans for FacesContext support?
gavin.king Sep 26, 2006 1:55 PM (in response to andrew.rw.robinson)No, Seam remoting is independent of JSF.
-
2. Re: Seam remoting -- any plans for FacesContext support?
andrew.rw.robinson Sep 26, 2006 5:03 PM (in response to andrew.rw.robinson)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