我遇到本地化问题。
我正在使用
JSF 2.0 Mojarra(xhtml而不是jsp)(2.02 - FCS) IceFaces Core 2.0.0 - beta1 IceFaces Compatibility Library v2.0.0。 - beta1
以下是xhtml页面的示例。
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<h:head>
<title>"#{msgs.pageTitle}"</title>
</h:head>
<h:body>
<h:form>
<br />
<div align="center"><h:commandButton
value="#{msgs.serbianLatinAlphabetName}"
actionListener="#{formSettings.swapLocale1}" immediate="true" /> <h:commandButton
value="#{msgs.serbianChyrilicAlphabetName}"
actionListener="#{formSettings.swapLocale1}" immediate="true" /><ice:commandButton
value="#{msgs.pageTitle}"
actionListener="#{formSettings.swapLocale1}" immediate="true"/></div>
</h:form>
</h:body>
</html>
和托管bean:
import java.io.*;
import java.util.*;
import javax.faces.bean.*;
import javax.faces.component.UIViewRoot;
import javax.faces.context.*;
import javax.faces.event.*;
@ManagedBean
@SessionScoped
public class FormSettings implements Serializable {
private boolean isDefault = true;
private Locale locale = new Locale("sr");
public void swapLocale1(ActionEvent event) {
switchLocale();
}
private void switchLocale() {
isDefault = !isDefault;
if (isDefault) {
locale = new Locale("sr_ME");
} else {
locale = new Locale("sr");
}
//FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot myViewRoot = context.getViewRoot();
myViewRoot.setLocale(locale);
}
public Locale getLocale() {
return locale;
}
public void swapLocale2(ValueChangeEvent event) {
Boolean flag = (Boolean)event.getNewValue();
if (flag) {
switchLocale();
}
}
public boolean isChecked() {
return(false);
}
public void setChecked(boolean flag) {}
}
我的web.xml如下:
<?xml version="1.0" encoding="ASCII"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>WePaminus</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
</web-app>
和faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<locale-config>
<default-locale>sr</default-locale>
<supported-locale>sr_ME</supported-locale>
</locale-config>
<resource-bundle>
<base-name>messages</base-name>
<var>msgs</var>
</resource-bundle>
</application>
</faces-config>
问题是,单击按钮后,区域设置不会更改。手动刷新后,显示了正确的区域设置。
你可以帮我解决这个问题。不得不说,在纯JSF 2.0(不包括icefaces)中实现的同一页面工作正常。由于
答案 0 :(得分:0)
您需要重新呈现整个页面或更好地触发同步请求而不是异步(ajaxical)请求仅部分呈现页面。