2 Replies Latest reply on Jan 13, 2010 10:30 PM by Kent Fletcher

    Need access to HttpServletResponse object within a seam component without using FacesContext

    Kent Fletcher Newbie

      Hello,


      I'm using GWT 1.7 and remoting (RPC) to a seam component using Seam 2.2.  I don't want to introduce the Faces API (namely javax.faces.context.FacesContext) to access the request/response object when we are not using Faces for presentation layer but using GWT instead.  I'm looking for a way to expose the request and response object to my seam component.




      @Name("com.myco.client.rpc.MyGWTSeamInterfaceService")
      public class MyGWTSeamServiceImpl implements MyGWTSeamInterfaceService {
           private static Logger log = Logger.getLogger(MyGWTSeamServiceImpl.class);
      
           @WebRemote
           public String getSomeHTML(String param) throws GException {
                
                /**
                 * org.jboss.seam.web.ServletContexts  exposes the HttpServletRequest, 
                 * so I'm not too worried here.
                 */
                HttpServletRequest request = ServletContexts.instance().getRequest();     
                
                /**
                 * But how do I get HttpServletResponse ?
                 */
                HttpServletResponse response = ?
                          
                response.setContentType("whatever");
                
                String html = "<p>HELLO WORLD</p>";
                return "<form name=\"someform\" action=\""+request.getContextPath()+"\">"+html+"</form>";
           }
      }








        • 1. Re: Need access to HttpServletResponse object within a seam component without using FacesContext
          Kent Fletcher Newbie

          I'm mainly looking to expose the HttpServletResponse object in my seam remoting component without introducing FacesContext since we are using GWT in this shop.


          • 2. Re: Need access to HttpServletResponse object within a seam component without using FacesContext
            Kent Fletcher Newbie

            I'm looking at seam source code here which exposes the request via static method but not the response...  This would be an ideal solution to my problem bypassing the FacesContext.




            /**
             * A Seam component that binds the HttpServletRequest object
             * to the current thread.
             * 
             * @author Gavin King
             */
            @Scope(ScopeType.EVENT)
            @Name("org.jboss.seam.web.servletContexts")
            @BypassInterceptors
            @Install(precedence=BUILT_IN)
            public class ServletContexts 
            {
               
               private HttpServletRequest request;
               
               public static ServletContexts instance()
               {
                  if ( !Contexts.isEventContextActive() ) 
                  {
                     throw new IllegalStateException("no event context active");
                  }
                  return (ServletContexts) Component.getInstance(ServletContexts.class, ScopeType.EVENT);
               }
               
               public static ServletContexts getInstance()
               {
                  return Contexts.isEventContextActive() ? 
                           (ServletContexts) Component.getInstance(ServletContexts.class, ScopeType.EVENT) : null;
               }
            
               public HttpServletRequest getRequest()
               {
                  return request;
               }
            
               public void setRequest(HttpServletRequest request)
               {
                  this.request = request;
               }
               
            }
            



            Just curious why HttpServletResponse is omitted?