JSF 2 upgrade component outside of form and outside of Facelet
I have a form in <ui: insert name = "content" /> When I save data using p: commandButton, I can update the form and things in the contents of <ui: insert name = "/>. But I find it hard to understand how update components in <ui: include src = "/sections/menus/topMenu.xhtml"/>
In the top menu, I have a preview for the panel with links that appear depending on whether the person is logged in or not. When they register, I show their username. If I update the username in the template content part, I want to update ui so that the name in the menu is also updated without refreshing the page. But this is a reserve that I can use too. Refresh the page after updating. But most likely it will not. I will write more code if you want, but try to minimize it to get started.
<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>
Below is the p: commandButton command, which stores user information
<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. -->
Below in the menu part of the template.
<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>
The general idea of accessing an element by identifier is as follows:
, <p:commandButton>.
, id JSF :
<button name="j_idt191" id="j_idt191" ....
, , JSF ID :
JSF:
<h:form>
<p:commandButton/>
</h:form>
HTML:
<form id="j_idt48">
<button name="j_idt48:j_idt191" id="j_idt48:j_idt191" ....
</form>
, . , ":" . :
<p:commandButton id="button1" update=":form:button2" ...
<h:form id="form">
<p:commandButton id="button2" update=":button1" ...
</h:form>
, JSF , - FireBug .
, , <f:subview> , topMenuLoginForm update=":topMenuLoginForm".
, AJAX, . . .
<p:gmap center="36.890257,30.707417" zoom="13" type="ROADMAP"
style="width:600px;height:400px"
model="#{mapBean.simpleModel}"
onPointClick="handlePointClick(event);"
widgetVar="cliMap" fitBounds="true"
id="map">
<p:ajax event="overlaySelect" listener="#{mapBean.onMarkerSelect}" />
</p:gmap>
<p:dialog widgetVar="dlg" showEffect="fade">
<h:form prependId="false" id="formnew">
<h:panelGrid columns="2">
<f:facet name="header">
<p:outputLabel value="New Point"/>
</f:facet>
<h:outputLabel for="title" value="Title:" />
<p:inputText id="title" value="#{mapBean.title}" />
<f:facet name="footer">
<p:commandButton value="Add" actionListener="#{mapBean.newPoint()}" update=":map" oncomplete="markerAddComplete()" />
<p:commandButton value="Cancel" onclick="return cancel()" />
</f:facet>
</h:panelGrid>
<h:inputHidden id="Nlat" value="#{mapBean.lat}" />
<h:inputHidden id="Nlng" value="#{mapBean.lng}" />
</h:form>
</p:dialog>
update = ": map", google Primefaces