here is the modified bean according to my requirement .
public class MenuBean implements Serializable {
private RichMenuBar initmenu;
public void createMenu(PhaseEvent phaseEvent) {
// check the menu is already added
AppModuleImpl menuAM = getAm();
System.out.println("in cretae menu metode");
boolean addMenu = true;
for (Iterator iterator = initmenu.getChildren().iterator(); iterator.hasNext();) {
UIComponent component = (UIComponent) iterator.next();
if ( component.getId().startsWith("menuId")){
addMenu = false;
}
}
if (addMenu) {
MyMenuImpl menuView = (MyMenuImpl)menuAM.getMyMenu1();
SubMyImpl Sub = menuAM.getSubMy1();
menuView.executeQuery();
while (menuView.hasNext()) {
MyMenuRowImpl menuItem = (MyMenuRowImpl)menuView.next();
System.out.println("in finding child");
Boolean menuFound = false;
RichMenu menu = new RichMenu();
String menuId = "menuId" + menuItem.getModId().toString();
// check if the main menu is already added
for (Iterator iterator = initmenu.getChildren().iterator(); iterator.hasNext(); ) {
UIComponent component = (UIComponent)iterator.next();
if (component.getId().equalsIgnoreCase(menuId)) {
menuFound = true;
menu = (RichMenu)component;
}
}
if (!menuFound) {
// new main menu
RichMenu newMenu = new RichMenu();
newMenu.setId(menuId);
newMenu.setText(menuItem.getMenuName());
System.out.println("the menu " + menuItem.getMenuName() );
//newMenu.setIcon(menuItem.getMenuIcon());
initmenu.getChildren().add(newMenu);
menu = newMenu;
}
//---------------------------------------------------------------------------------------
RowIterator submod = menuItem.getSubMy1();
while (submod.hasNext()){
SubMyRowImpl subMenu = (SubMyRowImpl)menuItem.getSubMy1();
Row subRow = submod.next();
String subName = (String)subRow.getAttribute("Sub");
Boolean menuItemFound = false;
String menuItemId = subName;
// check if the menu item is already added
for (Iterator iterator = menu.getChildren().iterator();
iterator.hasNext(); ) {
UIComponent component = (UIComponent)iterator.next();
if (component.getId().equalsIgnoreCase(menuItemId)) {
menuItemFound = true;
}
}
if (!menuItemFound) {
RichCommandMenuItem richMenuItem = new RichCommandMenuItem();
richMenuItem.setId(menuItemId);
richMenuItem.setText(subName);
System.out.println("the sub value name" + subName);
// richMenuItem.setActionExpression(getMethodExpression(menuItem.getAction()));
//richMenuItem.setIcon(menuItem.getIcon());
menu.getChildren().add(richMenuItem);
}
}
}
menuView.remove();
}
}
}
}