Menu实体类
@Entity
public class MyMenu implements Serializable {
private Long id;
private String type;
private String menuid;
private String pmenuid;
private String viewlabel;
private String link;
//getter and setter
...
}
Menu的Action
public class SimplePanelMenuAction {
@In(required = false)
private EntityManager entityManager;
@In(required = false)
@Out(required = false)
private MenuState menuState;
HtmlPanelMenu panelMenu;
public MenuState getMenuState() {
return menuState;
}
public void setMenuState(MenuState menuState) {
this.menuState = menuState;
}
public void select(ActionEvent event) {
menuState.setSelectedMenuItem(event.getComponent().getId());
}
private void loadMenu() {
panelMenu = new HtmlPanelMenu();
FacesContext facesContext = FacesContext.getCurrentInstance();
Class[] params = { ActionEvent.class };
Map
ActionListener actl= new MethodExpressionActionListener(Expressions.instance().createMethodExpression("#{simplePanelMenu1.select}", Void.TYPE, params).toUnifiedMethodExpression());
List
.createQuery(
"select m from MyMenu m where m.type = 'G' and m.pmenuid = '000000'")
.getResultList();
for (MyMenu mymenugrop : mymenugrops) {
HtmlPanelMenuGroup panelGroup = new HtmlPanelMenuGroup();
panelGroup.setId(mymenugrop.getViewlabel());
panelGroup.setName(mymenugrop.getViewlabel());
panelGroup.setLabel(mymenugrop.getViewlabel());
menu.put(panelGroup.getId(), false);
List
.createQuery(
"select m from MyMenu m where m.type = 'G' and m.pmenuid = :p1")
.setParameter("p1", mymenugrop.getMenuid()).getResultList();
for (MyMenu submymenugrop : submymenugrops) {
HtmlPanelMenuGroup subpanelGroup = new HtmlPanelMenuGroup();
subpanelGroup.setId(submymenugrop.getViewlabel());
subpanelGroup.setName(submymenugrop.getViewlabel());
subpanelGroup.setLabel(submymenugrop.getViewlabel());
List
.createQuery(
"select m from MyMenu m where m.type = 'I' and m.pmenuid = :p1")
.setParameter("p1", submymenugrop.getMenuid())
.getResultList();
for (MyMenu mymenuitem : mymenuitems) {
HtmlPanelMenuItem subpanelMenuItem = new HtmlPanelMenuItem();
subpanelMenuItem.setId(mymenuitem.getViewlabel());
subpanelMenuItem.setName(mymenuitem.getViewlabel());
subpanelMenuItem.setLabel(mymenuitem.getViewlabel());
subpanelMenuItem.addActionListener(actl);
subpanelMenuItem
.setActionExpression(Expressions.instance().createMethodExpression(mymenuitem.getLink()).toUnifiedMethodExpression());
subpanelGroup.getChildren().add(subpanelMenuItem);
}
panelGroup.getChildren().add(subpanelGroup);
}
List
.createQuery(
"select m from MyMenu m where m.type = 'I' and m.pmenuid = :p1")
.setParameter("p1", mymenugrop.getMenuid()).getResultList();
for (MyMenu mymenuitem : mymenuitems) {
HtmlPanelMenuItem panelMenuItem = new HtmlPanelMenuItem();
panelMenuItem.setId(mymenuitem.getViewlabel());
panelMenuItem.setName(mymenuitem.getViewlabel());
panelMenuItem.setLabel(mymenuitem.getViewlabel());
panelMenuItem.addActionListener(actl);
panelMenuItem
.setActionExpression(Expressions.instance().createMethodExpression(mymenuitem.getLink()).toUnifiedMethodExpression());
panelGroup.getChildren().add(panelMenuItem);
}
panelGroup.setValueExpression("value",Expressions.instance().createValueExpression("#{simplePanelMenu.menuState.menu['"+panelGroup.getLabel()+"']}").toUnifiedValueExpression());
panelMenu.getChildren().add(panelGroup);
menu.put(panelGroup.getLabel(), false);
}
menuState.setMenu(menu);
}
public HtmlPanelMenu getPanelMenu() {
if (panelMenu == null) {
loadMenu();
}
return panelMenu;
}
public void setPanelMenu(HtmlPanelMenu panelMenu) {
this.panelMenu=panelMenu;
}
@Remove
public void destroy() {
}
}
用于保存菜单状态的Bean
private Map
@In(required=false)
@Out(required=false)
private String selectedMenuItem;
public String getSelectedMenuItem() {
return selectedMenuItem;
}
public Map
return menu;
}
public void setMenu(Map
this.menu = menu;
}
public void setSelectedMenuItem(String selectedMenuItem) {
this.selectedMenuItem = selectedMenuItem;
}
public MenuState() {
}
}
页面:
iconExpandedGroup="disc"
iconCollapsedGroup="disc"
iconExpandedTopGroup="chevronUp"
iconGroupTopPosition="right"
iconCollapsedTopGroup="chevronDown"
iconCollapsedTopPosition="right" >