This discussion is archived
3 Replies Latest reply: Feb 28, 2012 10:03 AM by 424868 RSS

Changing locals in JSF 2 Facelets

424868 Newbie
Currently Being Moderated
Hi everybody,

I am working on a sample application using JSF 2 facelets which includes the "change local" functionality; I am using the following code to change the local to English:
public String englishAction() {
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(Locale.ENGLISH);
return null;
}
Unfortunately it only affects the current request despite the fact that the class that contains that code has the "session" scope. That means each time I go to another page I have to click the link for changing the local once again.
Earlier in JSF 1.2 we used to solve this problem by using the following code for JSP pages <f:view local="#{user.local}">. What is the alternative provided by Facelets in JSF 2 for the local attribute and which can remember the user local selection for the entire session?

Regards
  • 1. Re: Changing locals in JSF 2 Facelets
    gimbal2 Guru
    Currently Being Moderated
    Earlier in JSF 1.2 we used to solve this problem by using the following code for JSP pages <f:view local="#{user.local}">. What is the alternative provided by Facelets in JSF 2 for the local attribute and which can remember the user local selection for the entire session?
    Exactly where did you get the idea you shouldn't be using f:view anymore? You seem to be mistakenly thinking that it was a JSP tag, but it is in fact a faces tag. You see? F = Faces.

    Edited by: gimbal2 on Feb 28, 2012 2:05 AM
  • 2. Re: Changing locals in JSF 2 Facelets
    424868 Newbie
    Currently Being Moderated
    Dear sir,

    I am quite aware that the tag <f:view> is not part of the JSP set of tags and that F=Faces and that the <f:view> is part of the JSF framework. The problem is that it doesn't work when I use it with a facelet template.
  • 3. Re: Changing locals in JSF 2 Facelets
    424868 Newbie
    Currently Being Moderated
    Ok, I figured out now the reason why the view tag wasn't working with my template, now it is working fine. All I had to do is to move the view tag inside the body tag.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points