JSF的语言切换器和Ajax更新 [英] JSF Language switcher and ajax update
问题描述
此问题是后续 - 起来老语言切换器实现的JSF 2 。
This question is a follow - up of the older Language switcher implementation in JSF 2.
问题的实质仍然是有效的,尽管PrimeFaces已经发布了一些较新的版本,而我的JSF的知识比以前好一点。
The substance of the question is still valid, although PrimeFaces has released some newer builds, and my JSF knowledge is a bit better than before.
要总结一下,我有一个XHTML页面,完全Ajax化。
To summarize, I have a single xhtml page, fully ajaxified.
语言切换器是这样的:
<h:form id="selectLanguage" >
<p:commandLink action="#{languageSwitcher.setLanguage('it')}" rendered="#{languageSwitcher.language!='it'}" >
<h:graphicImage library ="images" name="it.gif" title="it" />
</p:commandLink>
<p:commandLink action="#{languageSwitcher.setLanguage('en')}" rendered="#{languageSwitcher.language!='en'}" >
<h:graphicImage library ="images" name="en.gif" title="en" />
</p:commandLink>
</h:form>
我想,当 是
选择,只有在 连接
标志显示,反之亦然。我想,在网页上的所有东西与资源包的翻译更新。
I want that when it
is chosen, only the en
flag is displayed, and viceversa. And I want that all the stuff in the web page is updated with the Resource Bundle translations.
在特别的,我有一些号码:对话框
(胡)的标题属性需要被更新。
对话框的形式是每个对话框里面:
In particular, I have some p:dialog
S whose header attributes need to be updated as well.
The dialog forms are inside each dialog:
<p:dialog header="#{msgs.myHeader}" ... >
<h:form .... />
</p:dialog >
在页面的其余部分是一个&LT;电话号码:布局&GT;
包含一些layoutUnits。每个 layoutUnit
包含了需要翻译以及其它组件的形式。
The rest of the page is a <p:layout>
containing some layoutUnits. Each layoutUnit
contains a form with other components that need to be translated as well.
LanguageSwitcher是 SessionScoped
JSF托管Bean
。
LanguageSwitcher is a SessionScoped
JSF Managed Bean
.
我已经尝试了所有通过以下方式:
I have tried all of the following ways:
-
&LT; F:AJAX渲染=@所有/&GT;
的P的内侧:commandLink
括号 -
更新=@所有的
里面的属性号码:commandLink
-
&LT;电话号码:AJAX更新=@所有/&GT;
在号码:commandLink
括号
<f:ajax render="@all" />
inside thep:commandLink
bracesupdate="@all"
attribute insidep:commandLink
<p:ajax update="@all" />
inside thep:commandLink
braces
不幸的是,他们没有工作。
Unfortunately, none of them works.
我曾尝试与 @all
,虽然我可插入的表格的ID,他们没有那么多。问题是,在对话框标题以这种方式不被更新。
I have tried with @all
, although I am available to insert the ids of the forms, they are not so many. Problem is that the dialog headers are not updated in this way.
我使用PrimeFaces 3.4.1 - Mojarra 2.1.13
I am using PrimeFaces 3.4.1 - Mojarra 2.1.13
推荐答案
在更新=@所有的
所有PrimeFaces版本到现在为止(3.4.2)是已知在IE中失败。任何JavaScript code随着Ajax响应传递不正确初始化。
The update="@all"
of all PrimeFaces versions until now (3.4.2) is known to fail in IE. Any JavaScript code delivered along with the ajax response isn't been initialized properly.
这是在此PrimeFaces论坛主题讨论一>并报告为问题4731 。
直到他们解决这个问题,最好的办法是通过加载下面的一段JavaScript的每个视图,它(可能)包含一个更新要解决它=@所有的
命令:
Until they fix it, your best bet is to workaround it by loading the following piece of JavaScript on every view which (possibly) contains an update="@all"
command:
var originalPrimeFacesAjaxResponseFunction = PrimeFaces.ajax.AjaxResponse;
PrimeFaces.ajax.AjaxResponse = function(responseXML) {
var newViewRoot = $(responseXML.documentElement).find("update[id='javax.faces.ViewRoot']").text();
if (newViewRoot) {
$('head').html(newViewRoot.substring(newViewRoot.indexOf("<head>") + 6, newViewRoot.indexOf("</head>")));
$('body').html(newViewRoot.substring(newViewRoot.indexOf("<body>") + 6, newViewRoot.indexOf("</body>")));
} else {
originalPrimeFacesAjaxResponseFunction.apply(this, arguments);
}
};
在由&LT加载的JS文件的香味提供此; H:outputScript目标=头&GT;
在&LT; H:身体GT;
,以执行正确的加载顺序
Provide this in flavor of a JS file which is loaded by <h:outputScript target="head">
inside the <h:body>
in order to enforce the right loading order.
<h:body>
<h:outputScript name="script.js" target="head" />
...
</h:body>
这篇关于JSF的语言切换器和Ajax更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!