4.0.0.CR1 - rich:panelMenu - binding to bean - not working
lucianoderiu Mar 7, 2011 3:24 PMHi,
I'm currently migrating my web app from Richfaces 3.3.2 (JSF1.2) to 4.0.0.CR1 (JSF2).
Things are going ok, after migrating a lot of the code i can log in to my app and see a panelMenu on the left and a tabPanel on the right. However the rich:panelMenu is bound to a backing bean which populates the panelMenu.
in the xhtml is have this...
<h:form> <rich:panelMenu id="MenuList" binding="#{MainBean.menu}" /> </h:form>
and in the backing bean (session scoped) i have...
private UIPanelMenu menupanel = new UIPanelMenu(); ... public UIPanelMenu getMenu(){ return this.menupanel; } public void setMenu(UIPanelMenu obj){ logger.debug("setting Menu"); this.menupanel=obj; }
I populate the menu when the bean is instantiated with the following...
public void setSearchText(String searchText){ this.searchText = (searchText==null)?"":searchText.toUpperCase(); logger.debug("Search Text --> "+this.searchText); this.menupanel.getChildren().clear(); this.menupanel.getChildren().addAll(buildMenu()); } public List<UIPanelMenuGroup> buildMenu(){ List<UIPanelMenuGroup> menuGroups = new ArrayList<UIPanelMenuGroup>(); ExpressionFactory expFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory(); ELContext elcontext = FacesContext.getCurrentInstance().getELContext(); for (TYPE type : TYPE.values()) { if(type==TYPE.HIDDEN) continue; //Never show hidden modules in menu UIPanelMenuGroup menuGroup = new UIPanelMenuGroup(); int count=0; for (MODULES mod : MODULES.values()) { if(mod.getType()==type){ if(up.hasAccessToModule(mod)){ if(mod.getName().toUpperCase().contains(this.searchText)){ UIPanelMenuItem item = new UIPanelMenuItem(); item.setId(type.name()+count); item.setLeftIcon(mod.getIconURI()); item.setLabel(mod.getName()); MethodExpression methodExpression = expFactory.createMethodExpression(elcontext, "#{MainBean.updateSelected}", String.class, new Class[]{}); item.setActionExpression(methodExpression); item.setRender("rightPanel"); item.setOncomplete("resize();"); //Create Param tag UIParameter param = new UIParameter(); param.setName(SELECTED_PARAM_NAME); param.setValue(mod.name()); item.getChildren().add(param); //Add Param to Item menuGroup.getChildren().add(item); count++; }else{ logger.debug("removing module from menu: "+mod.getName()); } }else{ logger.debug("User does not have access to: "+mod.getName()); } } } //Finish and return if(count>0){ menuGroup.setId(type.name()); int max = 3; int len = (menuGroup.getChildCount()+"").length(); StringBuilder label = new StringBuilder("("+menuGroup.getChildCount()+")"); while (len<max) { len++; label.append(" "); } label.append("- "); label.append(type.getName()); menuGroup.setLabel(label.toString()); if(type==TYPE.MAIN) menuGroup.setExpanded(true); menuGroups.add(menuGroup); } } return menuGroups; }
I've tried to simplify the scenario just in case i haven't understood how i should build the menu correctly for RF 4.x... I tried removing all the java side code except the standard getter and setter and i coded a couple of menu groups and menu items in the xhtml (exactly like in the RF 4.x showcase) the only addition to that was using the binding to the backing bean. As soon as i add the binding the panelMenu has no styling or functionality (see screenshot...)
Has anybody got any suggestions?
I was going to log a ticket but thought i should post on here just in case i am missing something daft!
Thanks
Luciano