3 Replies Latest reply on May 30, 2008 8:33 AM by nickarls

    loading stylesheets based on user agent

      Hi,


      Anyone been able to server stylesheets dynamically based on the users browser?


      Any ideas appreciated ;)


      Cheers


      Troy

        • 1. Re: loading stylesheets based on user agent
          nickarls

          Hmmm, just guessing here but you could EL-bind the stylesheet to a backing method that gets the request from the FacesContext and examines the headers for the browser version.


          It can probably be done more effective on client-side JS, though.

          • 2. Re: loading stylesheets based on user agent

            Good idea,


            I gave it a go but the FacesContext is not populating the requestHeaderMap. I thought this might be because it was being called on the render phase but it's not being populaed at all.


            I tried this:



            @Name("request")
            @Scope(ScopeType.EVENT)
            public class Request {

                 public String getAgent() {
                      FacesContext context = FacesContext.getCurrentInstance();
                      return context.getExternalContext().getRequestHeaderMap().get("AGENT");
                 }
            }



            I'm not sure whether AGENT is the right header,probably not but when I debugged nothing was in the requestHeaderMap


            Another anoying thing is xhtml seems to strip out comments so you can't do the standard:



            <!--[if lte IE 6]>
            <a4j:loadStyle src="/css/commonie6.css" />
            <![endif]-->



            This is a real problem - there seams to be no way to change the style sheets according to the browser, unless we use css hacks


            Troy

            • 3. Re: loading stylesheets based on user agent
              nickarls

              Tried (can be shortened down)


                    FacesContext facesContext = FacesContext.getCurrentInstance();
                    HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();
                    System.out.println(request.getHeader("user-agent"));
              


              ?