I'm fairly new to PrimeFaces and want to make a nice vertical menu bar, like the one theme roller has. Main options can be all collapsed, in fact they first show all collapsed, and just in case there is a huge list of inner options inside one or more, i want to make these inner options lazy loaded when the parent is expanded. All these collections are dynamic and load depending of granted profiles. I made it till the dynamic main options loading, using a one column data grid of fieldsets. The above works nicely, but when I expand one fieldset and fire the toggleListener, the population of inner options in the backing bean doesn't refresh the new content inside the fieldset (which is a tree).
Here's the code from the view:
Code: Select all
<h:form prependId="false" id="frmSideMenu">
<p:dataGrid value="#{userController.sideMenu}" var="menuL1" columns="1">
<p:column>
<p:fieldset toggleable="true" legend="#{menuL1.label}" collapsed="true"
toggleListener="#{menuL1.handleToggle}" onToggleUpdate="#{menuL1.id}Tree">
<p:outputPanel id="#{menuL1.id}Tree" >
<p:tree value="#{menuL1.root}" var="node" dynamic="true">
<p:treeNode>
<h:outputText value="#{node}"/>
</p:treeNode>
</p:tree>
</p:outputPanel>
</p:fieldset>
</p:column>
</p:dataGrid>
</h:form>
Code: Select all
public void handleToggle(ToggleEvent event) {
if (root.getChildren().size() <= 0) {
// Si no hay hijos, Popular los hijos del fieldset
TreeNode auxNode = new DefaultTreeNode("Option 1", root);
auxNode = new DefaultTreeNode("Option 2", root);
auxNode = new DefaultTreeNode("Option 3", root);
}
}