我在 <ui:insert name="content" /> 中有一个表单当我使用 ap:commandButton 保存数据时,我可以更新 <ui:insert name="content" /> 中的表单和内容。但我无法弄清楚如何更新 <ui:include src="/sections/menus/topMenu.xhtml"/> 中的组件
在顶部菜单中,我有一个面板的子视图,其中的链接取决于一个人是否登录。当他们登录时,我会显示他们的用户名。如果我在模板的内容部分更新用户名,我想更新 ui 以便菜单中的名称也更新而无需刷新页面。但这是我也可以使用的后备方案。更新后刷新页面。但宁愿不要。如果您愿意,我会发布更多代码,但尽量将其保持在最低限度。
<h:body>
<div id="wrap">
<div title="Container">
<ui:include src="/sections/base/header.xhtml"/>
</div><!-- End of Banner -->
<div id="baseTemplateTopMenu" title="Menu">
<ui:include src="/sections/menus/topMenu.xhtml"/>
</div><!-- End of Menu -->
<div id="sbt_contentbody">
<div title="Left Column">
<ui:include src="/sections/base/leftsidebar.xhtml"/>
</div> <!-- End of Left Column -->
<div title="Content Column">
<ui:insert name="content" />
</div><!-- End of Centre Column -->
<div title="Right Column">
<ui:include src="/sections/base/rightsidebar.xhtml"/>
</div><!-- End of Right Column -->
</div>
<div id="footer" title="Footer" class ="container">
<ui:include src="/sections/base/footer.xhtml"/>
</div><!-- End of Footer -->
</div><!-- End of Container -->
</h:body>
下面是保存用户信息的 p:commandButton
<p:commandButton id="id_SubmitUserInfoPrefs"
value="Update"
action="#{userPreferences.updateUserInfo()}" styleClass="bottom_margin_2em top_margin_2em">
<f:ajax execute="@form" render="@form :topMenuLoginView:topMenuLoginForm" />
<!-- tried adding 'update=":"topMenuLoginView:topMenuLoginForm"' as well. -->
下面是模板的菜单部分。
<f:subview id="topMenuLoginView">
<h:form id="topMenuLoginForm" prependId="false">
<ul>
<h:panelGroup id="loginPanel" rendered="#{!user.loggedIn}">
<li><h:outputLink value="javascript:void(0)" onclick="topMenuLoginDialog.show()"
title="login" styleClass="loginpanelclass">Log In</h:outputLink></li>
<li><h:link value="Register" outcome="/registration/register.xhtml" /></li>
</h:panelGroup>
<h:panelGroup id="logoutPanel" rendered="#{user.loggedIn}">
<li><h:link value="#{user.nickname}" outcome="#{navigationprops.userprefs}" /> </li>
<li><p:commandLink action="#{webAuthenticationBean.logout}"
update=":topMenuLoginView:topMenuLoginForm">
Logout
</p:commandLink>
</li>
</h:panelGroup>
</ul>
</h:form>
</f:subview>