I've made a dynamic menu, but I found my self with a problem, I cannot set the IDs to the elements.
I used the example code suggested in the another post, but it was of no use.aragorn wrote: ↑21 Nov 2016, 09:07I think this link can help to you for dynamic po:menu; http://www.primefaces.org/showcase/ui/menu/menu.xhtml (Please see Programmatic Menu section)
----
This would be a quick representation of my code (actually tested)
xhtml:
Code: Select all
...
<po:menu id="mainMenu" model="#{myBean.mainMenuModel}" />
...
Java bean:
Code: Select all
@ManagedBean
public class MyBean {
private MenuModel model;
@PostConstruct
public void init() {
model = new DefaultMenuModel();
// model = new DynamicMenuModel(); // this option does not work either
// Submenu
DefaultSubMenu mySubmenu = new DefaultSubMenu("Dynamic Submenu");
mySubmenu.setId("mySubmenu");
DefaultMenuItem item = new DefaultMenuItem("External");
item.setUrl("http://www.primefaces.org");
item.setId("myMenuItem");
mySubmenu.addElement(item);
model.addElement(mySubmenu);
}
public MenuModel getMainMenuModel() {
return model;
}
}
this generates:
ul #mainMenu
....|__ il #mainMenu_0
........|__ ul
............|__ il #mainMenu_0_0
myMenuItem and mySubmenu are nowhere to be seen.