2 Replies Latest reply on Mar 20, 2012 3:03 PM by devinderpal

    rich:contextMenu doesn't work when binding attribute is used

    devinderpal

      I'm trying to have dynamic number of menu items in rich:contextMenu. So I'm using binding attribute for this. But it doesn't show any context menu. It just shows firefox right click menu.

      Any help will be appreciated. Thanks.

       

      My XHTML file has below content:

      <h:outputLabel id="menutest" value="day">

        <rich:contextMenu mode="client" target="menutest" binding="#{calendarcontextmenu.contextMenu}">

        </rich:contextMenu>

       

      </h:outputLabel>

       

       

      The managed bean is as pasted below:

      @ManagedBean(name="calendarcontextmenu")

      public class CalendarContextMenuBinding

      {

                public UIContextMenu getContextMenu()

                {

                          UIContextMenu contextMenu = new UIContextMenu();

                          UIMenuItem menuItem = new UIMenuItem();

                          menuItem.setValue("Test 1");

                          UIMenuItem menuItem2 = new UIMenuItem();

                          menuItem2.setValue("Test 2");

       

                          contextMenu.getChildren().add(menuItem);

                          contextMenu.getChildren().add(menuItem2);

                          return contextMenu;

                }

      }


        • 1. Re: rich:contextMenu doesn't work when binding attribute is used
          mcmurdosound

          Which version do you use? RF 3.3.3 or 4.x?

           

                 UIContextMenu contextMenu = new UIContextMenu();

                              UIMenuItem menuItem = new UIMenuItem();

                              menuItem.setValue("Test 1");

                              UIMenuItem menuItem2 = new UIMenuItem();

                              menuItem2.setValue("Test 2");

           

          this work for RF 3.3.3. You'll have to use Application.createComponent(UIContextMenu.COMPONENT_TYPE) etc. to create valid components. Componentbinding is at least tricky: you'll have to keep the scope of your bean in mind. RequestScope!

           

          There is also an alternative: use some iterator in your facelet to create multiple ContextMenu entries ondemand.

           

          <a4j:repeat value="#{bean.contextMenuDTO}" var="item">

          <rich:menuItem ..../>

          </a4j:repeat>

           

          If this doesn't work. try <c:forEach>

          • 2. Re: rich:contextMenu doesn't work when binding attribute is used
            devinderpal

            I have tried by using Application.createComponent but that also doesn't work. I'm using RF4.2.0

            Have already tried using iterators - both a4j:repeat and c:forEach but none works. Please let me know if you have some other ideas.