Dynamic drop down menu RF 4.0
feedo123 Jan 6, 2014 9:57 AMHi I am creating a drop down menu dynamically, the menu items are database driven and I am able to see my drop downs and menu items in debugger. I am talking to the tune of 380 menu items within various sub groups.
We are migrating from Panel menu to drop down menu.
I checked a few posts in this community to overcome and i have adopted the solution given in this link.
dynamically creating dropDownMenu in Richfaces4
the jsp rendering the page is
<h:form id="form">
<rich:toolbar height="26px" >
<rich:dropDownMenu binding="#{dropdownMenuBean.ABC}" />
<rich:dropDownMenu binding="#{dropdownMenuBean.DEF}" />
......
</rich:toolbar>
</h:form>
</ui:composition>
I have customised a drop down menu bean which iterates and creates the groups and menu items and attaches it to the tool bar.
@ManagedBean
@ViewScoped
public class DropdownMenuBean {
private UIDropDownMenu abc, def, ghi, jkl, mno;
private FacesContext app;
private UIToolbar .......
public UIDropDownMenu getAbc() {
return Abc;
}
public void setAbc(UIDropDownMenu abc) {
this.abc = abc;
}
...
public DropdownMenuBean() {
app = FacesContext.getCurrentInstance();
menuBar = (UIToolbar) app.getApplication().createComponent(app,UIToolbar.COMPONENT_TYPE,"org.richfaces.ToolbarRenderer");
}
//this is called while we are logging in to create menus to avoid menu's being created multiple times
public void createDropDownMenu() {
menuBar = (UIToolbar) app.getApplication().createComponent(app,UIToolbar.COMPONENT_TYPE,"org.richfaces.ToolbarRenderer");
abc= (UIDropDownMenu) app.getApplication().createComponent(app,UIDropDownMenu.COMPONENT_TYPE, "org.richfaces.DropDownMenuRenderer");
label = (HtmlOutputText) app.getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
label.setValue("some constant");
abc.getFacets().put(UIDropDownMenu.Facets.label.name(), label);
abc.setMode(Mode.ajax);
abc.setHideDelay(0);
createMenu(abc, "same constant"); //this create menu creates the hierarchy, groups, menu items.
menuBar.getChildren().add(abc);
}
private void createMenu() {
does stuff
}
private void createGroup() {
creates groups
UIMenuGroup group = (UIMenuGroup) app.getApplication().createComponent(app,UIMenuGroup.COMPONENT_TYPE, "org.richfaces.MenuGroupRenderer");
}
private void createItem(UIComponentBase parent, ......) {
creates items
menuItem = (UIMenuItem) app.getApplication().createComponent(app, UIMenuItem.COMPONENT_TYPE, "org.richfaces.MenuItemRenderer");
addLink()..........
}
private void addLink(AbstractCommandLink comp, String action .....) {
..............
if (action != null) {
comp.setAction(FacesContext.getCurrentInstance().getApplication().
createMethodBinding(action, new Class[0]));
}
..............
}
I can see in the debugger the tool bar has a drop down - multiple menugroups - with menu items but for some reason its not rendering in the ui.
Pls help. (alternatives if i setup the component in the getter / setter of the dropdown, the dropdown with menu groups and items is being rendered. but this is not a solution for me.)