JSF 2 - Ajax - 表单未完全呈现
我使用新选择的语言环境呈现表单的 Ajax 代码是:
<h:selectOneMenu id="selectLang" immediate="true" value="#{langListing.language}">
<f:ajax listener="#{langListing.changeLocale}" render="@form" />
<f:selectItems value="#{langListing.languages}" />
</h:selectOneMenu>
但是,由于上述代码位于名为 header.xhtml 的头文件中,因此当我在英语和法语之间切换语言环境时,上述代码仅呈现 header.xhtml 的内容。我的index.xhtml结构如下:
header.xhtml
menu.xhtml
body content with an id of "contentSection"
footer.xhtml
如何在渲染header.xhtml的同时渲染menu.xhtml、body部分和footer.xhtml?
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>
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
How can I render menu.xhtml, the body section and footer.xhtml at the same time as I render header.xhtml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@form
仅影响父
的内容。请改用@all
。另请参阅
标记文档。但是,由于更改区域设置无论如何都会影响整个页面,因此您也可以考虑触发同步请求而不是 ajaxical 请求。要实现此目的,请删除
标记,向下拉列表添加onchange="submit()"
并将代码移至changeLocale( )
到setLanguage()
方法中。另请参阅此答案了解具体的例子。The
@form
affects the content of parent<h:form>
only. Use@all
instead.See also the description of the
render
attribute in<f:ajax>
tag documentation.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 aonchange="submit()"
to the dropdown and move the code insidechangeLocale()
intosetLanguage()
method. See also this answer for a concrete example.