Here's my server side code, located in a session bean called "sessionBean" :
Code: Select all
private transient MenuModel sideMenuModel;
public MenuModel getSideMenuModel() {
if (sideMenuModel == null) {
LOG.log(Level.INFO, "BUILDING MENU");
sideMenuModel = new DefaultMenuModel();
// collections
DefaultSubMenu subMenu = new DefaultSubMenu("Locations", "fa fa-location-arrow");
sideMenuModel.addElement(subMenu);
// smart reports
subMenu = new DefaultSubMenu("Smart Reports", "trending_up");
// dashboard
DefaultMenuItem item = new DefaultMenuItem("Dashboard", "dashboard","/charts.xhtml");
item.setIconPos("left");
subMenu.addElement(item);
// inventory
item = new DefaultMenuItem("Inventory", "view_list","/data.xhtml");
item.setIconPos("left");
subMenu.addElement(item);
sideMenuModel.addElement(subMenu);
// optional admin menu
if (isAdmin()) {
subMenu = new DefaultSubMenu("Admin", "settings");
item = new DefaultMenuItem("Edit Users", "group","/editUsers.xhtml");
item.setIconPos("left");
subMenu.addElement(item);
sideMenuModel.addElement(subMenu);
}
// utlities
item = new DefaultMenuItem("Utils", "fa fa-institution","/utils.xhtml");
sideMenuModel.addElement(item);
// documentation
item = new DefaultMenuItem("Documentation", "help","/docs.xhtml");
sideMenuModel.addElement(item);
}
return sideMenuModel;
}
Code: Select all
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pu="http://primefaces.org/ultima">
<h:form id="menuform">
<div class="layout-menu #{guestPreferences.menuClass}">
<div class="nano">
<div class="nano-content menu-scroll-content">
<pu:menu widgetVar="me" rendered="#{sessionBean.loggedIn}" model="#{sessionBean.sideMenuModel}"/>
</div>
</div>
</div>
</h:form>
</ui:composition>
If I change my code from using a "DefaultMenuModel" to construct this menu to instead "hard code" the menu, then everything works fine. I also tried adding my programatic menu to the demo project by adding in my sessionBean and the then adding this line of code to the menu.xhtml from the demo project just above the already defined menu ("me"):
Code: Select all
<pu:menu widgetVar="me2" rendered="#{sessionBean.loggedIn}" model="#{sessionBean.sideMenuModel}"/>