【发布时间】:2012-08-27 04:33:02
【问题描述】:
我在
在顶部菜单中,我有一个面板的子视图,其中的链接根据一个人是否登录而呈现。当他们登录时,我会显示他们的用户名。如果我在模板的内容部分更新用户名,我想更新 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>
【问题讨论】:
-
render="@form :topMenuLoginForm"并从该页面中删除<f:subview id="topMenuLoginView">怎么样? -
稍后会尝试。我需要开始行动,刚刚选择在完成时刷新页面。我将在本周晚些时候进行重构。
标签: ajax templates jsf-2 primefaces facelets