3 Replies Latest reply on Nov 10, 2006 11:29 AM by ssilvert

    Accessing Servlet Response from within Seam component

      Is there any way to access the HttpServletResponse within a Seam component? I ask since I need a component that handles downloading files; this needs to set the mime type, the header and the outpustream. I'd hate to develop a servlet just for this since I'd really like to use injection and the persistence context as part of this component.

      Any thoughts?

        • 1. Re: Accessing Servlet Response from within Seam component
          ssilvert

           

          "ngeadah" wrote:
          Is there any way to access the HttpServletResponse within a Seam component? I ask since I need a component that handles downloading files; this needs to set the mime type, the header and the outpustream. I'd hate to develop a servlet just for this since I'd really like to use injection and the persistence context as part of this component.

          Any thoughts?


          Avoid using the HttpServletResponse directly if you can. Use the ExternalContext instead. This should do it:

          @In (value="#{facesContext.externalContext}")
          private ExternalContext extCtx;
          .....
          .....
          .....
          extCtx.setResponseCharacterEncoding("encoding");

          • 2. Re: Accessing Servlet Response from within Seam component

            Is that not a JSF 1.2 method? I certainly don't see that method in javax.faces.context.ExternalContext...

            http://myfaces.apache.org/api/apidocs/index.html

            Any other thoughts?

            • 3. Re: Accessing Servlet Response from within Seam component
              ssilvert

               

              "ngeadah" wrote:
              Is that not a JSF 1.2 method? I certainly don't see that method in javax.faces.context.ExternalContext...

              http://myfaces.apache.org/api/apidocs/index.html

              Any other thoughts?


              Sorry. Yes, I was looking at the 1.2 javadoc. So for JSF 1.1 you would need to use the HttpServletResponse directly. My answer to your original question still applies. But the code looks like this instead:

              @In (value="#{facesContext.externalContext}")
              private ExternalContext extCtx;
              .....
              .....
              .....
              HttpServletResponse response = (HttpServletResponse)extCtx.getResponse();
              response.setChcaracterEncoding("myencoding");



              The main problem with this code is that it will break in a portlet environment.

              Stan