0 Replies Latest reply on Aug 26, 2011 2:17 AM by Savanna Johansen

    how to do dynamic binding on menu item in richfaces 4

    Savanna Johansen Newbie

      Hi! I wonder how we can do dynamic binding in richfaces 4. I have seen tutorials that work in previous versions of richfaces but not in this version.



      In my index.xhtml, i have definded a UIMenuItem like this:

      <rich:menuItem rendered="false"/>



      In the managed bean, I am doing these:

      UIMenuItem item = (UIMenuItem) ctx.getApplication().createComponent(ctx, UIMenuItem.COMPONENT_TYPE, "org.richfaces.MenuItemRenderer");


      Class[] params = {};


      MethodExpression action = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createMethodExpression(ctx.getELContext(),"#{bean.action}",String.class, params);


      MethodExpression actionListener = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createMethodExpression(ctx.getELContext(),"#{bean.action}",null, new Class[]{ActionEvent.class});



      item.addActionListener(new MethodExpressionActionListener(actionListener));



      The action method that was wired with the component only does this since I am only testing if the dynamic binding works:

      public String getAction() {

          System.out.println("It worked!");  

          return null;





      I tried binding it manually like this and it worked.

      <rich:menuItem rendered="false" binding="#{bean.action}"/>




      I just wonder how to do it dynamically... Any response would be appreciated.