将Facet添加到Primefaces中的动态菜单栏?

时间:2014-08-01 14:52:47

标签: jsf-2 primefaces

我知道如何生成动态菜单栏,但缺少的是添加一个方面,我将放置一个按钮"关闭会话系统"

如何从java按钮中添加...

我的代码java:

MenuModel model = new DefaultMenuModel();

DefaultSubMenu firstSubmenu = new DefaultSubMenu();
firstSubmenu.setIcon("ui-icon-document");
firstSubmenu.setId("File");
DefaultMenuItem item = new DefaultMenuItem("Crear Nuevo");
item.setId("newFile");
item.setOnclick("dlg.show()");
firstSubmenu.addElement(item); 
model.addElement(firstSubmenu);    

DefaultSubMenu secondSubmenu = new DefaultSubMenu();
secondSubmenu.setIcon("ui-icon-pencil");
secondSubmenu.setId("Edit");
DefaultMenuItem itemEditAplic = new DefaultMenuItem("Abrir Aplicación");
itemEditAplic.setId("EditAplic");
itemEditAplic.setOnclick("dlg.show()");
itemEditAplic.setCommand("#{cMantCliente.estadoActividad}");
itemEditAplic.setParam("aplicId", 2);
itemEditAplic.setUpdate(":menuBar");
secondSubmenu.addElement(itemEditAplic); 
model.addElement(secondSubmenu);    

DefaultSubMenu thirdSubmenu = new DefaultSubMenu("Aplicación");
thirdSubmenu.setIcon("ui-icon-image");
thirdSubmenu.setId("aplic");
DefaultMenuItem itemAplic = new DefaultMenuItem("Configuración General");
itemAplic.setId("ConfigGen");
itemAplic.setOnclick("/pages/configGeneral.jsf");
thirdSubmenu.addElement(itemAplic); 
model.addElement(thirdSubmenu);  

DefaultSubMenu fourSubMenu = new DefaultSubMenu("Alertas");
fourSubMenu.setIcon("ui-icon-info");
fourSubMenu.setId("info");
model.addElement(fourSubMenu); 

DefaultSubMenu fiveSubmenu = new DefaultSubMenu("Ayuda");
fiveSubmenu.setIcon("ui-icon-help");
fiveSubmenu.setId("help");
DefaultMenuItem helpItem = new DefaultMenuItem("Acerca de");
helpItem.setId("ConfigGen");
helpItem.setOnclick("/pages/help.jsf");
fiveSubmenu.addElement(helpItem); 
model.addElement(fiveSubmenu); 

1 个答案:

答案 0 :(得分:2)

我发现解决方案很简单,只需要添加动态菜单facet:

<p:menubar autoDisplay="false" styleClass="menu-bar" model="#{cLogin.model}">
    <f:facet name="options">
           <p:commandButton value="#{msg['form.boton.cerrar.session']}" icon="ui-icon-extlink" action="#{cLogin.logout}" />
    </f:facet>
</p:menubar>