在我的菜单中,我需要在子菜单中创建子菜单。我需要在我的MenuBean中执行此操作
下面是像我需要的图像:
下面是primefaces MenuBean的例子,但没有我想要的
//First submenu
DefaultSubMenu firstSubmenu = new DefaultSubMenu("Dynamic Submenu");
DefaultMenuItem item = new DefaultMenuItem("External");
item.setUrl("http://www.primefaces.org");
item.setIcon("ui-icon-home");
firstSubmenu.addElement(item);
model.addElement(firstSubmenu);
//Second submenu
DefaultSubMenu secondSubmenu = new DefaultSubMenu("Dynamic Actions");
item = new DefaultMenuItem("Save");
item.setIcon("ui-icon-disk");
item.setCommand("#{menuBean.save}");
item.setUpdate("messages");
secondSubmenu.addElement(item);
item = new DefaultMenuItem("Delete");
item.setIcon("ui-icon-close");
item.setCommand("#{menuBean.delete}");
item.setAjax(false);
secondSubmenu.addElement(item);
item = new DefaultMenuItem("Redirect");
item.setIcon("ui-icon-search");
item.setCommand("#{menuBean.redirect}");
secondSubmenu.addElement(item);
model.addElement(secondSubmenu);
答案 0 :(得分:2)
您可以将SubMenus添加到SubMenus中。按照你给我们的例子,我做了一些安排,你可以看到我的意思:
//First submenu
DefaultSubMenu firstSubmenu = new DefaultSubMenu("Dynamic Submenu");
DefaultMenuItem item = new DefaultMenuItem("External");
item.setUrl("http://www.primefaces.org");
item.setIcon("ui-icon-home");
firstSubmenu.addElement(item);
//Second submenu
DefaultSubMenu secondSubmenu = new DefaultSubMenu("Dynamic Actions");
item = new DefaultMenuItem("Save");
item.setIcon("ui-icon-disk");
item.setCommand("#{menuBean.save}");
item.setUpdate("messages");
secondSubmenu.addElement(item);
item = new DefaultMenuItem("Delete");
item.setIcon("ui-icon-close");
item.setCommand("#{menuBean.delete}");
item.setAjax(false);
secondSubmenu.addElement(item);
item = new DefaultMenuItem("Redirect");
item.setIcon("ui-icon-search");
item.setCommand("#{menuBean.redirect}");
secondSubmenu.addElement(firstSubmenu); //child inside a child
secondSubmenu.addElement(item);
model.addElement(secondSubmenu);
答案 1 :(得分:0)
这是示例(ManagedBean):
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
public class MenuBean {
public void save(ActionEvent actionEvent) {
addMessage("Data saved");
}
public void update(ActionEvent actionEvent) {
addMessage("Data updated");
}
public void delete(ActionEvent actionEvent) {
addMessage("Data deleted");
}
public void addMessage(String summary) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
这适用于您的xhtml页面:
<h:form>
<p:growl id="messages"/>
<p:menubar autoSubmenuDisplay="true">
<p:submenu label="File" icon="ui-icon ui-icon-document">
<p:submenu label="New" icon="ui-icon ui-icon-contact">
<p:menuitem value="Project" url="#" helpText="CTRL+N" />
<p:menuitem value="Other" url="#" helpText="CTRL+O"/>
</p:submenu>
<p:menuitem value="Open" url="#" />
<p:menuitem value="Quit" url="#" />
</p:submenu>
<p:submenu label="Edit" icon="ui-icon ui-icon-pencil">
<p:menuitem value="Undo" url="#" icon="ui-icon ui-icon-arrowreturnthick-1-w" helpText="CTRL+Z"></p:menuitem>
<p:menuitem value="Redo" url="#" icon="ui-icon ui-icon-arrowreturnthick-1-e" helpText="CTRL+Y"></p:menuitem>
</p:submenu>
<p:submenu label="Help" icon="ui-icon ui-icon-help">
<p:menuitem value="Contents" url="#" />
<p:submenu label="Search" icon="ui-icon ui-icon-search">
<p:submenu label="Text">
<p:menuitem value="Workspace" url="#" />
</p:submenu>
<p:menuitem value="File" url="#" />
</p:submenu>
</p:submenu>
<p:submenu label="Actions" icon="ui-icon ui-icon-gear">
<p:submenu label="Ajax" icon="ui-icon ui-icon-refresh">
<p:menuitem value="Save" actionListener="#{buttonBean.save}" icon="ui-icon ui-icon-disk" update="messages"/>
<p:menuitem value="Update" actionListener="#{buttonBean.update}" icon="ui-icon ui-icon-arrowrefresh-1-w" update="messages"/>
</p:submenu>
<p:submenu label="Non-Ajax" icon="ui-icon ui-icon-newwin">
<p:menuitem value="Delete" actionListener="#{buttonBean.delete}" icon="ui-icon ui-icon-close" update="messages" ajax="false"/>
</p:submenu>
</p:submenu>
<p:menuitem value="Quit" url="http://www.primefaces.org" icon="ui-icon ui-icon-close" />
</p:menubar>
</h:form>