1 2 Previous Next 15 Replies Latest reply on Jun 8, 2012 2:35 PM by wael.boughzala

    4.0.0.CR1 - rich:panelMenu - binding to bean - not working

    lucianoderiu

      Hi,

       

      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...)

       

       

      panelMenu-with binding.png

       

      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

        • 1. 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
          nbelaevski

          Hi Luciano,

           

          You are creating components incorrectly, application.createComponent(FacesContext, String, String) should be used for that.

          • 2. 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
            lucianoderiu

            Thanks Nick,

             

            I've changed it to use the following, but it's still the same...

             

            private UIPanelMenu menupanel = (UIPanelMenu) app.createComponent(FacesContext.getCurrentInstance(),"org.richfaces.PanelMenu","org.richfaces.PanelMenuRenderer");

             

            I can't seem to find any info from googleing it either so not sure if thats correct?

             

            Thanks

            Luciano

            • 3. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
              lucianoderiu

              I've been playing around with lots of different things and i can see several javascript errors in Chrome saying 'Uncaught TypeError: undefined is not a function'. This appears just after the menu so i'm assume its not able to load the javascript/css.

               

              I dont know why this would be but if i add a blank panelMenu to the page it works, the menu has styling and sends ajax requests...

               

              <h:form style="width:200px; height:100%; ">   
                  <rich:panelMenu id="MenuList"  binding="#{MainBean.menu}"/>                                                                     
              
                  <rich:panelMenu />
              </h:form>
              

               

               

               

              panelMenu-with binding2.png

               

              Does that make any sense?

               

              Thanks

              Luciano

              • 4. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                ilya_shaikovsky

                works fine for me using latest code.

                 

                tried

                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                <ui:composition xmlns="http://www.w3.org/1999/xhtml"

                          xmlns:h="http://java.sun.com/jsf/html"

                          xmlns:f="http://java.sun.com/jsf/core"

                          xmlns:ui="http://java.sun.com/jsf/facelets"

                          xmlns:a4j="http://richfaces.org/a4j"

                          xmlns:rich="http://richfaces.org/rich">

                          <h:form>

                                    <rich:panelMenu binding="#{pMenu.menu}"/>

                          </h:form>

                </ui:composition>

                 

                and

                @ManagedBean

                @RequestScoped

                public class PMenu {

                    private UIPanelMenu menu = null;

                 

                 

                    public PMenu() {

                        menu = (UIPanelMenu)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenu");

                        UIPanelMenuGroup group =(UIPanelMenuGroup)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuGroup");

                        group.setLabel("group1");

                        group.setId("gr1");

                        UIPanelMenuItem item = (UIPanelMenuItem)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuItem");

                        item.setLabel("item1");

                        item.setId("itm1");

                        group.getChildren().add(item);

                        item = (UIPanelMenuItem)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuItem");

                        item.setLabel("item2");

                        item.setId("itm2");

                        group.getChildren().add(item);

                        menu.getChildren().add(group);

                        group =(UIPanelMenuGroup)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuGroup");

                        group.setLabel("group2");

                        group.setId("gr2");

                        item = (UIPanelMenuItem)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuItem");

                        item.setLabel("item3");

                        item.setId("itm3");

                        group.getChildren().add(item);

                        item = (UIPanelMenuItem)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuItem");

                        item.setLabel("item4");

                        item.setId("itm4");

                        group.getChildren().add(item);

                        menu.getChildren().add(group);

                        item = (UIPanelMenuItem)FacesContext.getCurrentInstance().getApplication().createComponent("org.richfaces.PanelMenuItem");

                        item.setLabel("item5");

                        item.setId("itm5");

                        menu.getChildren().add(item);

                    }

                   

                    public void setMenu(UIPanelMenu menu) {

                        this.menu = menu;

                    }

                 

                 

                    public UIPanelMenu getMenu() {

                        return menu;

                    }

                 

                 

                }

                • 5. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                  ilya_shaikovsky

                  Sorry, It worked because I had declarative menu near the dynamic one and resources were loaded for both. Yes it's a problem but purelly related to JSF2 (even submitted as issue but need to search additionally in JSF tracker). JSF do not get the rendererType properly if you using createComponent(type) so ned to specify explicitly. And here is the code which works(note that rendererType now passed to create component):

                   

                  package org.richfaces.demo;

                   

                   

                  import javax.faces.application.Application;

                  import javax.faces.bean.ManagedBean;

                  import javax.faces.bean.RequestScoped;

                  import javax.faces.context.FacesContext;

                   

                   

                  import org.richfaces.component.UIPanelMenu;

                  import org.richfaces.component.UIPanelMenuGroup;

                  import org.richfaces.component.UIPanelMenuItem;

                   

                   

                  @ManagedBean

                  @RequestScoped

                  public class PMenu {

                      private UIPanelMenu menu = null;

                   

                   

                      public PMenu() {

                          FacesContext fc = FacesContext.getCurrentInstance();

                          Application application = FacesContext.getCurrentInstance().getApplication();

                          menu = (UIPanelMenu) application.createComponent(fc, UIPanelMenu.COMPONENT_TYPE, "org.richfaces.PanelMenuRenderer");

                          UIPanelMenuGroup group = (UIPanelMenuGroup) application.createComponent(fc, UIPanelMenuGroup.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuGroupRenderer");

                          group.setLabel("group1");

                          group.setId("gr1");

                          UIPanelMenuItem item = (UIPanelMenuItem) application.createComponent(fc, UIPanelMenuItem.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuItemRenderer");

                          item.setLabel("item1");

                          item.setId("itm1");

                          group.getChildren().add(item);

                          item = (UIPanelMenuItem) application.createComponent(fc, UIPanelMenuItem.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuItemRenderer");

                          item.setLabel("item2");

                          item.setId("itm2");

                          group.getChildren().add(item);

                          menu.getChildren().add(group);

                          group = (UIPanelMenuGroup) application.createComponent(fc, UIPanelMenuGroup.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuGroupRenderer");

                          group.setLabel("group2");

                          group.setId("gr2");

                          item = (UIPanelMenuItem) application.createComponent(fc, UIPanelMenuItem.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuItemRenderer");

                          item.setLabel("item3");

                          item.setId("itm3");

                          group.getChildren().add(item);

                          item = (UIPanelMenuItem) application.createComponent(fc, UIPanelMenuItem.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuItemRenderer");

                          item.setLabel("item4");

                          item.setId("itm4");

                          group.getChildren().add(item);

                          menu.getChildren().add(group);

                          item = (UIPanelMenuItem) application.createComponent(fc, UIPanelMenuItem.COMPONENT_TYPE,

                              "org.richfaces.PanelMenuItemRenderer");

                          item.setLabel("item5");

                          item.setId("itm5");

                          menu.getChildren().add(item);

                      }

                   

                   

                      public void setMenu(UIPanelMenu menu) {

                          this.menu = menu;

                      }

                   

                   

                      public UIPanelMenu getMenu() {

                          return menu;

                      }

                   

                   

                  }

                  • 6. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                    lucianoderiu

                    Thanks for your reply,

                     

                    I've tried specifying the rendereType explicitly but i still have the same issue. I also tried replacing my java code with your code but it was the same result.

                     

                    I did notice something else whilst i was trying all this out... if i add in the second panelMenu it loads the resource if i refresh the page (F5), however if i render the panelMenu (and tabPanel) on the page via ajax it doesn't load the resources.

                     

                    I render the 'mainWrapper' outputPanel which contains a ui:include...

                     

                    <a4j:outputPanel id="mainWrapper" style="display:none;" layout="block">

                                                    <ui:include  src="#{guiMB.viewId}"/>

                    </a4j:outputPanel>

                     

                    Is this ajax rendering also a JSF2 issue?

                     

                    Thanks

                    Luciano

                    • 7. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                      ilya_shaikovsky

                      tried ajax rendering using

                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                      <html xmlns="http://www.w3.org/1999/xhtml"

                                xmlns:h="http://java.sun.com/jsf/html"

                                xmlns:f="http://java.sun.com/jsf/core"

                                xmlns:ui="http://java.sun.com/jsf/facelets"

                                xmlns:a4j="http://richfaces.org/a4j"

                                xmlns:rich="http://richfaces.org/rich">

                       

                       

                      <h:head></h:head>

                       

                       

                      <h:body>

                                <f:view contentType="text/html">

                                          <h:form>

                                                    <rich:tabPanel switchType="ajax">

                                                              <rich:tab header="Overview">

                                                                        <h:graphicImage value="/images/icons/common/rf.png"

                                                                                  style="float:right" />

                                          RichFaces is a component library for JSF and an advanced framework for

                                          easily integrating AJAX capabilities into business applications.

                                          <ul>

                                                                                  <li>100+ AJAX enabled components in two libraries</li>

                                                                                  <li>a4j: page centric AJAX controls</li>

                                                                                  <li>rich: self contained, ready to use components</li>

                                                                                  <li>Whole set of JSF benefits while working with AJAX</li>

                                                                                  <li>Skinnability mechanism</li>

                                                                                  <li>Component Development Kit (CDK)</li>

                                                                                  <li>Dynamic resources handling</li>

                                                                                  <li>Testing facilities for components, actions, listeners,

                                                                                  and pages</li>

                                                                                  <li>Broad cross-browser support</li>

                                                                                  <li>Large and active community</li>

                                                                        </ul>

                                                              </rich:tab>

                                                              <rich:tab header="JSF 2 and RichFaces 4">

                                                                        <h:form>

                                                                                  <rich:panelMenu binding="#{pMenu.menu}" />

                                                                        </h:form>

                                                              </rich:tab>

                                                    </rich:tabPanel>

                                          </h:form>

                                </f:view>

                      </h:body>

                      </html>

                       

                      so panel menu at second tab with the same bean. And it works fine for me using latest code.

                      • 8. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                        ilya_shaikovsky

                        yes.. checked with ui:include and can see the problem.. but not really sure that something that we could fix.. so proposed workaround to add rich:panelMenu with rendered=false to the main page (which contain include) and we will additionally check.

                        • 9. 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                          lucianoderiu

                          Thanks Ilya but that workaround isn't going to be suitable for my application because there is only the 1 real page request when you first hit the url and after that everything else is rendered via ajax. So i would need to add every possible component to the login page of my app and i dont want to do that.

                           

                          I've logged a tickect on the JSF Jira... http://java.net/jira/browse/JAVASERVERFACES-2016

                           

                          Thanks for your help

                           

                          Luciano

                          • 10. 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                            lucianoderiu

                            Hi Ilya,

                             

                            I just found out that the binding issue works correctly with the MyFaces JSF libs.

                             

                            The ui:inlcude issue is also present in MyFaces libs.

                             

                            Luciano

                            • 11. 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                              lucianoderiu

                              I've created the same Jira ticket on the MyFaces Jira for the ui:include issue... https://issues.apache.org/jira/browse/MYFACES-3106

                              • 12. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                                ranveer.singh

                                Hi IIya,

                                Did you try the sample in SessionScope ?  It comes like given below. First time it renders properly , but once you refresh it comes like this. Please help in this. I am stuck with this behavior.

                                 

                                after.png

                                • 13. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                                  sedgewick

                                  Hi,

                                   

                                  i have exactly the same behaviour, dynamically building the menu from a sesson scoped bean!

                                  Could you solve the problem?

                                  Please let me know your fix!

                                   

                                  Thanks for your response.

                                  • 14. Re: 4.0.0.CR1 - rich:panelMenu - binding to bean - not working
                                    ranveer.singh

                                    As suggested by Ilya, I removed the component creation from the session bean. You need to build the compoenent for every request.

                                    I put my model data in session scope and reusing the data while building the component (in order to avoid the multiple database call).

                                    1 2 Previous Next