Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Up to now I had the same problem you mention and your post gave me the clue to resolve it. I intended to do exactly what you're trying to do so I hope my solution can help you. </p> <p>My index page, that contains the menu and the container in which the content is updated:</p> <pre><code>&lt;ui:composition template="./../resources/templates/template.xhtml"&gt; &lt;ui:define name="content"&gt; &lt;h:form&gt; &lt;h:panelGroup layout="block" styleClass="menu"&gt; &lt;ui:include src="./../resources/templates/menu.xhtml"/&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup layout="block" id="content"&gt; &lt;h:panelGroup layout="block" styleClass="content" rendered="#{menuBacking.albums}"&gt; &lt;ui:include src="albums.xhtml"/&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup layout="block" styleClass="content" rendered="#{menuBacking.band}"&gt; &lt;ui:include src="band.xhtml"/&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup layout="block" styleClass="content" rendered="#{menuBacking.concerts}"&gt; &lt;ui:include src="concerts.xhtml"/&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup layout="block" styleClass="content" rendered="#{menuBacking.contacts}"&gt; &lt;ui:include src="contacts.xhtml"/&gt; &lt;/h:panelGroup&gt; &lt;/h:panelGroup&gt; &lt;/h:form&gt; &lt;/ui:define&gt; &lt;/ui:composition&gt; </code></pre> <p>The menu included in the first panelGroup:</p> <pre><code>&lt;p:menu&gt; &lt;p:menuitem value="Albums" action="#{menuBacking.active}" update="content"&gt; &lt;f:setPropertyActionListener value="albums" target="#{menuBacking.selection}"/&gt; &lt;/p:menuitem&gt; &lt;p:menuitem value="Band" action="#{menuBacking.active}" update="content"&gt; &lt;f:setPropertyActionListener value="band" target="#{menuBacking.selection}"/&gt; &lt;/p:menuitem&gt; &lt;p:menuitem value="Concerts" action="#{menuBacking.active}" update="content"&gt; &lt;f:setPropertyActionListener value="concerts" target="#{menuBacking.selection}"/&gt; &lt;/p:menuitem&gt; &lt;p:menuitem value="Contacts" action="#{menuBacking.active}" update="content"&gt; &lt;f:setPropertyActionListener value="contacts" target="#{menuBacking.selection}"/&gt; &lt;/p:menuitem&gt; &lt;/p:menu&gt; </code></pre> <p>This is one of the pages I want to display into the content area (just for test purpose):</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;body&gt; Contacts &lt;/body&gt; </code></pre> <p>And finally, the bean:</p> <pre><code>@ManagedBean @SessionScoped public class MenuBacking implements Serializable { private String selection; private boolean albums; private boolean band; private boolean concerts; private boolean contacts; public MenuBacking() { albums = false; band = true; // You can define the default page that will be show concerts = false; contacts = false; } // getters &amp; setters public void active() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException { setAlbums(selection.equals("albums")); setBand(selection.equals("band")); setConcerts(selection.equals("concerts")); setContacts(selection.equals("contacts")); } } </code></pre> <p>Be aware the difference between action and actionListener. Action first assigns the value to the property and then execute the method, while actionListener execute the method and then assigns the value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload