If your application have a general requirement that a menu which has all of its children (menu items , go menu items , sub menus) disabled then the menu should also be disabled, then instead of writing the same conditions that you had to the children to the menu (boring and error prone) you can just use the following.
1. bind the af:menu to the backing bean, that is the binding prop eg. binding="#{myBacking .myMenu}"
2. set the disable property of the af:menu to a backing bean property e.g. disabled="#{myBacking .myMenuDisabled}"
//The backing bean methodpublic boolean isMyMenuDisabled() {
return isMenuDisabled(this.myMenu);
}
3.In the backing property method use the following method (you can decide if it should be placed to a generic class eg Backing beans Super class or in a Utils class as a statis method (e.g. like methods in ADFUtils))
/** * In order to be disabled ALL children (&&) must be disabled
* @param menu
* @return
*/
protected boolean isMenuDisabled(RichMenu menu) {
boolean isDisabled = true;
List children = menu.getChildren();
logger.debug("parse children ");
Iterator iter = children.iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof RichMenu) {
RichMenu childMenu = (RichMenu)o;
logger.trace("Found submenu with id: "+childMenu.getId());
boolean isChildMenuDisabledProperty = childMenu.isDisabled();
if (isChildMenuDisabledProperty ) {
isDisabled = isDisabled && isChildMenuDisabledProperty;
logger.trace("submenu with id:"+childMenu.getId()+" returned (prop based) : " +
isChildMenuDisabledProperty);
}
else {
boolean isChildMenuIsDisabled = isMenuDisabled(childMenu);
isDisabled = isDisabled && isChildMenuIsDisabled;
logger.trace("submenu with id:"+childMenu.getId()+" returned (parsed) : " + isChildMenuIsDisabled);
}
} else if (o instanceof RichCommandMenuItem) {
RichCommandMenuItem menuItem = (RichCommandMenuItem)o;
isDisabled = isDisabled && menuItem.isDisabled();
logger.debug("Found menuItem with id: " + menuItem.getId() + " and disabled condition: " +
menuItem.isDisabled());
} else if (o instanceof RichGoMenuItem) {
RichGoMenuItem goMenuItem = (RichGoMenuItem)o;
isDisabled = isDisabled && goMenuItem.isDisabled();
logger.debug("Found gomenuItem with id: " + goMenuItem.getId() + " and disabled condition: " +
goMenuItem.isDisabled());
} else if (o instanceof RichSeparator) {
logger.debug("separator found. ingnoring...");
} else {
logger.info("Not Supported. Menu Item can only have: menu, menuItem, goMenuItem ot separator.");
}
}
logger.debug("NEW implementation returns: " + isDisabled);
return isDisabled;
}
It supports that the menu can have as its children:
° Sub menus
° menuItems
° goMenuItems
You can check other props also like visible and rendered prop.
I ll try to upload a full example when I ll get so time :(
Enjoy
Spido