11 Replies Latest reply on Mar 31, 2009 4:25 AM by sebekk23

    panelMenu - selectedChild

    krzysgdynia

      I want to use panelMenu to navigation in my application.
      I created session bean to save selectedChild and linked it with panelMenu and use expanded attribute.
      Almost everything works fine but:
      - after refresh page I lost selected item in panelMenu
      - I must use expanded attribute because use only selectedChild attribute doesn't work

      How should I set attributes in panelMenu that panelMenu remember state (selected item) between pages ?
      What do I wrong ?

      Thanks for any help


      @Name("menuRend")
      @Scope(ScopeType.CONVERSATION)
      public class MenuRendering {
      
       private String activeItem;
      
       public String getActiveItem() {
       return activeItem;
       }
      
       public void setActiveItem(String activeItem) {
       this.activeItem = activeItem;
       }
      
       public String addSlStopnieAwans() {
       activeItem = "dodajStopienAwansu";
       return "/sl_stopnie_awansu/SlStopnieAwansuEdit.xhtml";
       }
      
       public String showStopnieAwans() {
       activeItem = "pokazStopnieAwansu";
       return "/sl_stopnie_awansu/SlStopnieAwansuList.xhtml";
       }
      ....
      

       <a4j:form id="form" ajaxSubmit="true" reRender="body" limitToList="true">
       <rich:panelMenu style="width:170px; " mode="ajax"
       iconExpandedGroup="disc" iconCollapsedGroup="disc"
       iconExpandedTopGroup="chevronUp" iconGroupTopPosition="right"
       iconCollapsedTopGroup="chevronDown" iconCollapsedTopPosition="right" selectedChild="#{menuRend.activeItem}" expandSingle="true" expandMode="ajax" rendered="#{identity.loggedIn}" >
       <rich:panelMenuGroup label="#{msg['view.miasta.title']}" expanded="#{menuRend.activeItem=='dodajMiasto' || menuRend.activeItem=='listaMiast' ? true : false}">
       <rich:panelMenuItem label="#{msg['view.miasta.dodaj']}" action="#{menuRend.addMiasto}" name="dodajMiasto">
       <f:param name="miastaPkM"/>
       </rich:panelMenuItem>
       <rich:panelMenuItem label="#{msg['view.miasta.lista']}" action="#{menuRend.showMiasta}" name="listaMiast"/>
       </rich:panelMenuGroup>
       <rich:panelMenuGroup label="#{msg['view.jednostki.title']}" expanded="#{menuRend.activeItem=='dodajJednostke' || menuRend.activeItem=='listaJednostek' ? true : false}" >
       <rich:panelMenuItem label="#{msg['view.jednostki.dodaj']}" action="#{menuRend.addJednostka}" name="dodajJednostke"/>
       <rich:panelMenuItem label="#{msg['view.jednostki.lista']}" action="#{menuRend.showJednostki}" name="listaJednostek"/>
       </rich:panelMenuGroup>
      ......
      


        • 1. Re: panelMenu - selectedChild
          krzysgdynia

          Your ideas on how to do this is appreciated.
          Please anyone can help me ?

          • 2. Re: panelMenu - selectedChild
            krzysgdynia

            knock, knock
            Is anybody here ?

            • 3. Re: panelMenu - selectedChild
              krzysgdynia

              Why nobody answer?

              • 4. Re: panelMenu - selectedChild
                krzysgdynia

                ...

                • 5. Re: panelMenu - selectedChild
                  mail.micke

                  I'm also interested in the solution to this.

                  Trying out different richfaces components for navigation but having problems with saving selection state as well.

                  • 6. Re: panelMenu - selectedChild
                    dragospd

                    It seems that the selectedChild is a readonly attribute, it is not set when selecting an item. I don't know why. Someone with other ideas?

                    • 7. Re: panelMenu - selectedChild
                      mmichalek

                      I'm also having problems with the selectedChild attribute. According to the docs, I would have thought this would work similarly to panelBar.selectedPanel, but I haven't gotten it to work with panelMenu.

                      Is there a JIRA opened on this?

                      • 8. Re: panelMenu - selectedChild
                        stevy

                        Have you found a solution for that? I'm facing the same problem.

                        • 9. Re: panelMenu - selectedChild
                          ilya_shaikovsky
                          • 10. Re: panelMenu - selectedChild
                            sebekk23

                            Solution for that is:
                            xhtml

                            ...
                            <rich:panelMenu expandSingle="true" iconItem="triangle" expandMode="client" selectedChild="#{defaultNavigationBackingBean.selectedMenuGroup}"
                             id="navigationPanelMenu">
                             <rich:panelMenuGroup label="Informacje" id="information">
                             <rich:panelMenuItem label="Lista jeden" action="# {defaultNavigationBackingBean.commonPublicationListLink}"
                             actionListener="#{defaultNavigationBackingBean.leaveSelectedItem}"/>
                            ...
                            

                            bean (defaultNavigationBackingBean) [scope: session]
                            ...
                            define some static fields with id of groups (you will need them to set selectedMenuGroup) for example:
                             private final static String INFORMATION_GROUP = "information"
                            
                            private String itemId;
                            private String selectedMenuGroup;
                            public String getSelectedMenuGroup() {
                             if(this.selectedMenuGroup != null)
                             {
                             FacesContext context = FacesContext.getCurrentInstance();
                             ((HtmlPanelMenuGroup)context.getViewRoot().findComponent(this.selectedMenuGroup)).setExpanded(true);
                            
                            ((HtmlPanelMenuItem)context.getViewRoot().findComponent(this.itemId)).setStyle("font-style:italic;font-weight:bold;");
                             context = null;
                             }
                             return this.selectedMenuGroup;
                            }
                            public void setSelectedMenuGroup(String selectedMenuGroup) {
                             this.selectedMenuGroup = selectedMenuGroup;
                            }
                            public void leaveSelectedItem(ActionEvent e) {
                             UIComponent component = e.getComponent();
                             if(component instanceof HtmlPanelMenuItem)
                             this.itemId = ((HtmlPanelMenuItem)component).getId();
                            }
                            public String someInformationAction()
                            {
                             this.selectedMenuGroup = INFORMATION_GROUP;
                             return "action";
                            }
                            ...
                            


                            It's hard to set styles in editor :) ... so sorry for that ;)

                            • 11. Re: panelMenu - selectedChild
                              sebekk23

                              Solution for that is:
                              xhtml

                              ...
                              <rich:panelMenu expandSingle="true" iconItem="triangle" expandMode="client" selectedChild="#{defaultNavigationBackingBean.selectedMenuGroup}"
                               id="navigationPanelMenu">
                               <rich:panelMenuGroup label="Informacje" id="information">
                               <rich:panelMenuItem label="Lista jeden" action="# {defaultNavigationBackingBean.commonPublicationListLink}"
                               actionListener="#{defaultNavigationBackingBean.leaveSelectedItem}"/>
                              ...
                              

                              bean (defaultNavigationBackingBean) [scope: session]
                              ...
                              define some static fields with id of groups (you will need them to set selectedMenuGroup) for example:
                               private final static String INFORMATION_GROUP = "information"
                              
                              private String itemId;
                              private String selectedMenuGroup;
                              public String getSelectedMenuGroup() {
                               if(this.selectedMenuGroup != null)
                               {
                               FacesContext context = FacesContext.getCurrentInstance();
                               ((HtmlPanelMenuGroup)context.getViewRoot().findComponent(this.selectedMenuGroup)).setExpanded(true);
                              
                              ((HtmlPanelMenuItem)context.getViewRoot().findComponent(this.itemId)).setStyle("font-style:italic;font-weight:bold;");
                               context = null;
                               }
                               return this.selectedMenuGroup;
                              }
                              public void setSelectedMenuGroup(String selectedMenuGroup) {
                               this.selectedMenuGroup = selectedMenuGroup;
                              }
                              public void leaveSelectedItem(ActionEvent e) {
                               UIComponent component = e.getComponent();
                               if(component instanceof HtmlPanelMenuItem)
                               this.itemId = ((HtmlPanelMenuItem)component).getId();
                              }
                              public String someInformationAction()
                              {
                               this.selectedMenuGroup = INFORMATION_GROUP;
                               return "action";
                              }
                              ...
                              


                              It's hard to set styles in editor :) ... so sorry for that ;)