Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.7DR#2
-
Component/s: Framework
-
Labels:None
-
Environment:n/a
Description
-
Hide
- Test_DynamicLocale.war
- 5.30 MB
- Michael Thiem
-
- META-INF/MANIFEST.MF 0.0 kB
- WEB-INF/classes/.../PreferenceBean.class 1 kB
- WEB-INF/classes/.../messages_de.properties 0.1 kB
- WEB-INF/classes/.../messages_en.properties 0.1 kB
- WEB-INF/faces-config.xml 0.6 kB
- WEB-INF/html_basic.tld 244 kB
- WEB-INF/jsf_core.tld 25 kB
- WEB-INF/lib/backport-util-concurrent.jar 343 kB
- WEB-INF/lib/commons-beanutils.jar 100 kB
- WEB-INF/lib/commons-collections.jar 164 kB
- WEB-INF/lib/commons-digester.jar 96 kB
- WEB-INF/lib/commons-fileupload.jar 52 kB
- WEB-INF/lib/commons-logging.jar 27 kB
- WEB-INF/lib/el-api.jar 24 kB
- WEB-INF/lib/el-ri.jar 97 kB
- WEB-INF/lib/jsf-api.jar 324 kB
- WEB-INF/lib/jsf-impl.jar 602 kB
- WEB-INF/lib/jstl.jar 17 kB
- WEB-INF/.../krysalis-jCharts-1.0.0-alpha-1.jar 151 kB
- WEB-INF/lib/standard.jar 343 kB
- WEB-INF/lib/xercesImpl.jar 1.15 MB
- WEB-INF/lib/xml-apis.jar 190 kB
- WEB-INF/web.xml 3 kB
- index.jsp 0.2 kB
- main.jspx 0.9 kB
- WEB-INF/lib/icefaces.jar 744 kB
- WEB-INF/lib/icefaces-comps.jar 1.48 MB
-
Hide
- Test_DynamicLocale.zip
- 29 kB
- Michael Thiem
-
- Test_DynamicLocale/.project 1 kB
- Test_DynamicLocale/.../messages_en.properties 0.1 kB
- Test_DynamicLocale/.../messages_de.properties 0.1 kB
- Test_DynamicLocale/.../PreferenceBean.java 0.7 kB
- Test_DynamicLocale/.../messages_en.properties 0.1 kB
- Test_DynamicLocale/.../messages_de.properties 0.1 kB
- Test_DynamicLocale/.../PreferenceBean.class 1 kB
- Test_DynamicLocale/WebRoot/.../web.xml 3 kB
- Test_DynamicLocale/.../faces-config.xml 0.6 kB
- Test_DynamicLocale/.../.faces-config.mex 0.1 kB
- Test_DynamicLocale/.../html_basic.tld 244 kB
- Test_DynamicLocale/WebRoot/.../jsf_core.tld 25 kB
- Test_DynamicLocale/WebRoot/.../MANIFEST.MF 0.0 kB
- Test_DynamicLocale/WebRoot/index.jsp 0.2 kB
- Test_DynamicLocale/WebRoot/main.jspx 0.9 kB
- Test_DynamicLocale/.mymetadata 0.3 kB
- Test_DynamicLocale/.classpath 0.5 kB
Issue Links
- depends on
-
ICE-2485 Set Ajax request header Accept-Language from previous lifecycle's Locale
- Closed
Activity
- All
- Comments
- History
- Activity
- Remote Attachments
- Subversion
demo application, tested on tomcat 5.5
source code for test application
I fixed ICE-1505, and along with Mircea, ICE-2485, which partially addresses this issue. Basically, now you can call UIViewRoot.setLocale(Locale) and it sticks. Here's an application code example:
Bean.java
public SelectItem[] getLocales() {
ArrayList items = new ArrayList();
Application application = FacesContext.getCurrentInstance().getApplication();
Iterator supportedLocales = application.getSupportedLocales();
while (supportedLocales.hasNext())
SelectItem[] locales = new SelectItem[items.size()];
items.toArray(locales);
return locales;
}
public String getSelectedLocale()
{ Locale selectedLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); return selectedLocale.toString(); } public void setSelectedLocale(String localeString) {
Application application = FacesContext.getCurrentInstance().getApplication();
Iterator supportedLocales = application.getSupportedLocales();
while (supportedLocales.hasNext()) {
Locale locale = (Locale) supportedLocales.next();
if(locale.toString().equals(localeString))
}
}
page.jspx
<ice:selectOneMenu value="#
{bean.selectedLocale}" partialSubmit="true">
<f:selectItems value="#
"/>
</ice:selectOneMenu>
faces-config.xml
<faces-config >
<application>
<locale-config>
<default-locale>en_US</default-locale>
<supported-locale>fr_CA</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>en_US</supported-locale>
<supported-locale>en_CA</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
</application>
...
</faces-config >
I'm looking into why using <f:view locale="#
{prefs.locale}"> doesn't seem to work. But, quite separately from that, is the issue that f:loadBundle does not work with dynamic locales. I'll explain why in a later comment. But basically, we'll have to roll our own if we want message bundle values to dynamically update in a long-lived request.
The <f:loadBundle> tag isn't really Ajax/ICEfaces friendly, when used with JSP. But, it works just fine with Facelets though.
The JSF 1.2 JSP tag for it takes the messages.properties file, parses it all into a Map object, and throws it into the request map. So, since our JSP Tag code only runs once, when we build the component tree, then it won't update the bundle text if you change locales. The JSF 1.2 <f:loadBundle> JSP Tag code has a JSF 1.1 compatibility mode that will make an actual UIComponent in the component tree, that will put that Map into the request map on every render. BUT, it doesn't rebuild that Map, but just re-puts the same old Map in every time.
On the other hand, with Facelets, we reevaluate the FaceletHandlers on every render pass, and the Facelets LoadBundleHandler does NOT cache the Map, but grabs it fresh from the ResourceBundle every time. I've tested the component-showcase, where we have American and English spellings of "Colour", and it does change dynamically.
Similarly to the <f:loadBundle> issue, <f:view locale="#
{prefs.locale}"> doesn't work with JSP. I read the JSF 1.2 source-code, and saw that com.sun.faces.taglib.jsf_core.ViewTag.setProperties(UIComponent) is where UIViewRoot.setLocale(Locale) should be called. But it's not. That's probably because we special-case the Tag handling for <f:view> in our JSP parsing code, and do something that interferes with it.
I haven't empirically tested it with Facelets, but I read its com.sun.facelets.tag.jsf.core.ViewHandler class, and think that it should work fine there. There's one caveat though, that UIViewRoot.getLocale() will try to return its locale field first, before trying to evaluate the ValueBinding / ValueExpression. So, D2DViewHandler setting an initial Locale, will interfere with this.
So, that gives two tasks to do:
1. Fix ICEfaces JSP ViewTag handling, so that ViewTag.setProperties(UIComponent) is called, with UIViewRoot as the argument.
2. Make D2DViewHandler.createView() not call UIViewRoot.setLocale( calculateLocale(context) ) which is kind of redundant anyway.
Fixed #2 with a subsequent commit for ICE-1505.
#1 has been spun off into ICE-2551, to be fixed in the next release.
Automated regression test failed on Feb. 1 @ 10pm. Likely related to changes in ICE-2551. Re-opened.
Unfortunately FacesContext.getCurrentInstance().getViewRoot().setLocale(locale) do not work in my environment: ICEFaces 1.7.2 SP1 + Seam 2.1SP1. I tried this to make workaround for problem with non-working Seam's LocaleSelector (ICE-2147) but have no success.
Hi,
I have exactly the same issue. using Netbeans 6.5 (ICEFaces 1.7.2).
The call to FacesContext.getCurrentInstance().getViewRoot().setLocale(locale) doesn't seem to work at all.
This piece of code was working fine in Netbeans 6.1 (Woodstock components).
Any suggestion would be very welcome.
Is it possible that this is again an issue in ICEfaces 1.8 RC1? I've upgraded the libraries for testing purposes in an existing project and I'm experiencing this behaviour now.
I'm setting the locale by FacesContext.getCurrentInstance().getViewRoot().setLocale(locale).
I believe the right thing to do would be to modify the order of the supported locales (see Application.setSupportedLocales) or just change the default locale (see Application.setSupportedLocale).