My Ajax codes for rendering a form using a newly-selected locale are:
<h:selectOneMenu id="selectLang" immediate="true" value="#{langListing.language}">
<f:ajax listener="#{langListing.changeLocale}" render="@form" />
<f:selectItems value="#{langListing.languages}" />
</h:selectOneMenu>
然而,由于上述codeS在头文件名为header.xhtml,上述codeS只会使header.xhtml的内容时,我切换英语和法语的语言环境。我的index.xhtml结构如下:
However, since the above codes in in a header file called header.xhtml, the above codes only render the content of header.xhtml when I switch locales between English and French. My index.xhtml structure is as follow:
header.xhtml
menu.xhtml
body content with an id of "contentSection"
footer.xhtml
我怎样才能使名为menu.xhtml,同时身体部分和footer.xhtml为我呈现header.xhtml?
How can I render menu.xhtml, the body section and footer.xhtml at the same time as I render header.xhtml?
推荐答案
在 @form
影响父母的含量&LT; H:形式GT;
只。使用 @all
代替。
The @form
affects the content of parent <h:form>
only. Use @all
instead.
<f:ajax listener="#{langListing.changeLocale}" render="@all" />
另见的 &LT; F:。AJAX&GT;
标记文档
See also the description of the render
attribute in <f:ajax>
tag documentation.
然而,由于更改区域反正影响整个页面,你也可以考虑以触发同步请求,而不是ajaxical之一。要做到这一点,删除&LT; F:AJAX&GT;
标签中,添加一个的onchange =提交()
来下拉移动内部的code changeLocale()
到 setLanguage()
方法。另请参见this回答以一个具体的例子。
However, since changing the locale affects the entire page anyway, you could also consider to fire a synchronous request instead of an ajaxical one. To achieve this, remove the <f:ajax>
tag, add a onchange="submit()"
to the dropdown and move the code inside changeLocale()
into setLanguage()
method. See also this answer for a concrete example.
相关推荐
最新文章