Jsf 2 区域设置可以';不能改变
我试图使用primefaces更改区域设置,但徒劳无功,下面是我的bean代码:Jsf 2 区域设置可以';不能改变,jsf-2,primefaces,Jsf 2,Primefaces,我试图使用primefaces更改区域设置,但徒劳无功,下面是我的bean代码: // more imports here @ManagedBean @SessionScoped public class DateBean implements Serializable{ private Date startDate, endDate; private Locale locale = FacesContext.getCurrentInstance().getViewRoot().get
// more imports here
@ManagedBean
@SessionScoped
public class DateBean implements Serializable{
private Date startDate, endDate;
private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
public void setLocale(Locale locale) {
this.locale = locale;
}
public Locale getLocale(){
return locale;
}
public void changeLocale(String loc){
FacesContext context = FacesContext.getCurrentInstance();
locale = new Locale(loc);
context.getViewRoot().setLocale(locale);
}
}
facelet:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<f:view locale="#{dateBean.locale}">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
<h:outputScript library="scripts" name="#{dateBean.locale}.js"></h:outputScript>
</h:head>
<h:body>
<h:form>
<p:commandButton value="de" action="#{dateBean.changeLocale('de')}" >
<p:ajax update="@form" process="@form"></p:ajax>
</p:commandButton>
<p:calendar id="cc" value="#{dateBean.startDate}" required="true" showOn="both"
requiredMessage="Start date required"/>
<p:message for="cc"></p:message>
</h:form>
</h:body>
</f:view>
</html>
在此处插入标题
当我点击区域设置按钮时,日历区域设置不会更改为deutsch,我也没有得到任何例外。
但是,使用旧的JSF2.*CommandButton组件执行此任务就像微风一样:
<h:commandButton value="portugal" action="#{dateBean.changeLocale('pt')}" >
<f:ajax render="@form"></f:ajax>
</h:commandButton>
你们能帮我弄清楚吗?Primefaces库的组件不提供德语翻译。您需要下载javascript片段并将其附加到代码中。然后,使日历使用所需的
区域设置
。看看这个,你有更多关于你的问题的信息
您还根据您的语言环境(
)包含一个Javascript文件,该文件根据您的语言环境自动包含Javascript文件。由于您只是在ajax请求中刷新h:form
部分,因此您可能会遇到麻烦,因为此标记是在整个视图中呈现的,因此您的翻译文件目前不适用于您的区域设置。合适的解决方案:只需包含从一开始就需要的所有javascript文件。我已经这样做了,先生,问题不在于.js语言,谢谢。那么有两种可能:您的{dateBean.locale}
没有获得正确的值,或者您的日历区域设置没有正确设置。为什么不试试日历中的locale=“#{dateBean.locale}”
属性呢?AFAK日历的locale属性不是必需的,因为它已经使用Action event进行了更改,但是在添加locale属性后仍然不起作用,这真的让我很不安,谢谢查看您实际的{dateBean.locale}
值为。在屏幕上打印出来。它打印出en_US,然后只使用事件操作按钮进行更改