JSF 2 - 阿贾克斯 - 表格不会完全呈现表格、JSF、阿贾克斯

由网友(万幸得以相知)分享简介:我的阿贾克斯codeS使用一个新选择的区域呈现形式是:My Ajax codes for rendering a form using a newly-selected locale are:我的阿贾克斯codeS使用一个新选择的区域呈现形式是:

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.

阅读全文

相关推荐

最新文章