3 Replies Latest reply on Feb 6, 2006 12:30 PM by gavin.king

    Correct way to access FacesContext

    stijn.dewitt

      Hello,

      I am trying to have an entity bean return different messages based on the user's preferred locale, based on settings in the user's profile, cookie, browser preferences, and default locale, in that order. I am currently just making a singleton localizer class that accesses the facescontext like this:

      FacesContext context = FacesContext.getCurrentInstance();
      Locale requestLocale = context.getExternalContext().getRequestLocale();

      Is there a 'Seam way' of doing this? I noticed a Seam FacesContext in the api docs. Or is there a smarter way of handling i18n with Seam altogether?

      Thanks for building such a promising framework, keep it up!

        • 1. Re: Correct way to access FacesContext
          gavin.king

          The way you are doing it is actually perfectly OK.

          A more Seamy way is to use:

          @In FacesContext facesContext;


          But this is really just a matter of taste.

          • 2. Re: Correct way to access FacesContext
            stijn.dewitt

            Thanks for your answer Gavin!

            @In FacesContext facesContext;


            Would I be correct in saying that the above code is to be used for Seam-aware components, while the standard JSF syntax is preferred for non-Seam-aware code?

            [Offtopic]
            I have tried a lot of different web frameworks for Java, and I wanted to try JSF for a while now, but it always seemed so complex that I postponed it...until I discovered Seam. I'm a JSF newbie as well as a Seam newbie, so if I ask JSF questions, sorry...Your 'reward' for making JSF so easy for newbies I'm afraid.. :)
            [/Offtopic]



            • 3. Re: Correct way to access FacesContext
              gavin.king

              Yes, as I said, there is no problem at all with FacesContext.getCurrentInstance().