3 Replies Latest reply on Jan 9, 2008 5:45 PM by nbelaevski

    PanelMenu problem with dynamic creation of menu items

    crisyag

      Hello list,

      I'm trying to create a panel menu dynamically, but it is not working. When user clicks on a commandLink, I have a method that adds a new item group and item to the panelMenu, it works well but sometimes the new item is not added or replaces the previous added item. Please, can anyone help me with this problem?

      Thanks,

      Cristiane Yaguinuma.

        • 1. Re: PanelMenu problem with dynamic creation of menu items
          nbelaevski

          Please provide some more info

          • 2. Re: PanelMenu problem with dynamic creation of menu items
            crisyag

            Hello Nick, thanks for your answer.

            I have changed my code to use a h:PanelGrid with SimpleTogglePanels instead of PanelMenu, but I still have the same problem, some panels are not created dynamically, others replaces previous ones.

            I have a tree, each node is a commandLink:

            <a4j:commandLink reRender="chatTestPanel" value="#{contact.name}" action="#{ContactList.actionContactClick}">
             <a4j:actionparam name="selectedContact" value="#{contact.id}"/>
            </a4j:commandLink>
            


            In backing bean I add a new SimpleTogglePanel to a PanelGrid in the method ContactList.actionContactClick:

            public void actionContactClick() {
             String contactId = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("selectedContact");
             HtmlSimpleTogglePanel panel = new HtmlSimpleTogglePanel();
             panel.setLabel(contactId);
             panel.setOpened(false);
             panel.setId("id_" + this.idCount);
             panel.setSwitchType("client");
             this.chatWindowPanelGrid.getChildren().add(panel);
             this.idCount++;
            }
            


            In the code above, this.chatWindowPanelGrid is binded to a h:PanelGrid defined in jsp. This PanelGrid is empty at first and then is filled by the previous method. The problem is that some panels are not added to this.chatWindowPanelGrid.getChildren() and sometimes panels are replaced. I tried an alternative solution, at least is working but I need to test more. I have a list called chatList in my backing bean that keeps the chatWindowPanelGrid children:

            this.chatList.add(panel);
            chatWindowPanelGrid.getChildren().clear();
            chatWindowPanelGrid.getChildren().addAll(chatList);
            


            By doing this, chatWindowPanelGrid contains all panels added in the correct order. So, the problem is related to the children list of PanelGrid, the same problem I had with PanelMenu children.

            Again, thanks for the help.

            Cristiane Yaguinuma.

            • 3. Re: PanelMenu problem with dynamic creation of menu items
              nbelaevski

              Hmm, I do not see anything that could cause the problem. Could you please prepare sample project to see the problem? You can send it to nbelaevski at exadel dot com