8 Replies Latest reply on Jul 10, 2006 7:51 PM by JBoss Fan

    How to tweak output based on HTTP header for wired/mobile cl

    David Bernstein Newbie

      I'm creating an application that I'd like to be accessible from both PCs and mobile phones. Not too surprisingly, I want to present somewhat different XHTML in the two cases, and I'd like to do it based on the HTTP User-Agent header. For the most part I'm happy with what's generated by Seam, but I'd like to be able to intercept what's generated (preferably with objects representing the output, rather than string parsing) and have some fine-grained control over a few but not all generated output. I'm using Seam with facelets. I think my specific questions are:

      1. How do I read an HTTP header value that was passed by the client?
      2. How do I intercept the (partially?) rendered output, tweak it, and send it on its way?
      3. Can Seam (and facelet) XHTML be made to operate nicely *without* the use of javascript?

      Suggestions as well as pointers to existing documentation and/or examples that I've missed will be gratefully accepted.

      Thanks,
      David

        • 1. Re: How to tweak output based on HTTP header for wired/mobil
          Pete Muir Master

           

          1. How do I read an HTTP header value that was passed by the client?


          I think FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap(); will contain this.

          2. How do I intercept the (partially?) rendered output, tweak it, and send it on its way?


          I haven't done this, but perhaps a servlet filter?

          3. Can Seam (and facelet) XHTML be made to operate nicely *without* the use of javascript?


          This was discussed on the facelets list within the last week - I would suggest you take a look, and perhaps follow up there?

          • 2. Re: How to tweak output based on HTTP header for wired/mobil
            Gavin King Master

            For "tweaking", a servlet filter seems the right approach. Perhaps you might like to take a look at SiteMesh for this kind of work? If so, let me know how well sitemesh integrates with Seam...

            I also added this issue, though it is probably not what you want:

            http://jira.jboss.com/jira/browse/JBSEAM-299

            • 3. Re: How to tweak output based on HTTP header for wired/mobil
              David Bernstein Newbie

              Pete,

              Thanks for the hints. Could you please give the URL for the facelets list you mentioned?

              Gavin,

              I'll look into SiteMesh, thanks. Would it make sense to add the current FacesContext to the FacesApplicationContext or to make it a separately injectable component? Would this be a good way to set response headers too?

              Thank you both,
              David

              • 4. Re: How to tweak output based on HTTP header for wired/mobil
                Gavin King Master

                Sorry?

                @In FacesContext facesContext

                works.

                • 5. Re: How to tweak output based on HTTP header for wired/mobil
                  David Bernstein Newbie

                  Yes, you're right. For example in my XHTML file:

                  User-Agent: <b><h:outputText value="#{facesContext.externalContext.requestHeaderMap['User-Agent']}"/></b>
                  


                  I think that I was thrown off by looking at the source code instead of taking the right part of the reference manual at face value... ;-)

                  • 6. Re: How to tweak output based on HTTP header for wired/mobil
                    Pete Muir Master

                    http://facelets.dev.java.net is the facelets homepage, it's linked off there, nabble carries it, perhaps others.

                    Gavin et al, this is perhaps something that that should be on the FAQ. In fact, can the FAQ be a wiki page so it is easily editable? Or developed on the wiki or something?

                    • 7. Re: How to tweak output based on HTTP header for wired/mobil
                      David Bernstein Newbie

                      Putting a little information about this (dependence or lack thereof of javascript) in the Seam documentation area would be very helpful I think, particularly to people like me new to Seam/JSF/facelets/MyFaces/EJB3/JavaPersistence. I think that there's a large population of people like me who are Java-competent who need to create web apps and trying to decide whether to go forward with more recent Java stuff or move (defect?) to Ruby on Rails. Anything that gets people like this going will be hepful. I will admit as a newbie to this that the boundaries between the several projects/APIs I mentioned above are only slowly becoming clear, even with considerable reading from several sources.

                      • 8. Re: How to tweak output based on HTTP header for wired/mobil
                        JBoss Fan Newbie

                         

                        "dbatcn" wrote:
                        Putting a little information about this (dependence or lack thereof of javascript) in the Seam documentation area would be very helpful I think, particularly to people like me new to Seam/JSF/facelets/MyFaces/EJB3/JavaPersistence.


                        Completly agree, it looks like seam documentation assumes some degree of competency with JSF, EJB (less in v3 due to Pojos but container managed concepts are needed, and other basics).
                        Maybe a section like: "Things to Know About Underlying Frameworks in Seam" would be a good idea.

                        In particular Seam has been a breeze for me as I'm very close to JSF, EJB and Java5, but to compete (catch up?) with Rails some minimal background in underlying frameworks is needed, and that could be a consideration for many as you mentioned Java developers.

                        In regards to your original question, what about creating (or reusing) a pluggable JSF renderer. Something that Seam would be somewhat agnostic to -if not mistaken-
                        Jsf renderers idea was that in principle: to server different clients.

                        Yeyo

                        "dbatcn" wrote:

                        I think that there's a large population of people like me who are Java-competent who need to create web apps and trying to decide whether to go forward with more recent Java stuff or move (defect?) to Ruby on Rails. Anything that gets people like this going will be hepful. I will admit as a newbie to this that the boundaries between the several projects/APIs I mentioned above are only slowly becoming clear, even with considerable reading from several sources.