【发布时间】:2014-10-13 17:44:55
【问题描述】:
我正在尝试动态生成菜单栏,我已经得到了结果,但是我有一个方法来检查 DefaultSubMenu 是否已经存在,如果子菜单存在,则不必创建它,它必须返回该子菜单,但是找到时会不断生成相同的子菜单,这就是方法
public DefaultSubMenu buildSubMenu(OpcionesMenu opcionPrincipal) throws Exception{
DefaultSubMenu subMenu=null;
try {
if(getMenu()==null){
DefaultSubMenu newSubmenu=new DefaultSubMenu(opcionPrincipal.getIdOpcionMenu().toString());
newSubmenu.setId(opcionPrincipal.getNombreMenu());
newSubmenu.setIcon(opcionPrincipal.getIcono());
newSubmenu.setLabel(opcionPrincipal.getNombreMenu());
subMenu= newSubmenu;
}else{
//Checking the list of DefaultSubMenu
List<MenuElement> opciones=getMenu().getElements();
boolean validador=false;
for (MenuElement me : opciones) {
if(me.getId().equals(opcionPrincipal.getNombreMenu())){
validador=true;// if it is found
subMenu=(DefaultSubMenu)me;
}
}
if(!validador){if not found i create the submenu
DefaultSubMenu newSubmenu=new DefaultSubMenu(opcionPrincipal.getIdOpcionMenu().toString());
newSubmenu.setId(opcionPrincipal.getNombreMenu());
newSubmenu.setIcon(opcionPrincipal.getIcono());
newSubmenu.setLabel(opcionPrincipal.getNombreMenu());
subMenu=newSubmenu;
}
}
return subMenu;
} catch (Exception e) {
throw new Exception(
"Error en la clase UsuarioOpcionMenuController - metodo buildSubMenu\n"
+ e.getMessage(), e.getCause());
}
}
你能帮帮我吗?
【问题讨论】:
标签: jsf primefaces menubar