2 Replies Latest reply on Apr 30, 2010 8:22 AM by pomcompot

    rich:panelBar and selectedPanel

    pomcompot

      Hi,

       

      I got problems saving the state of the selected panel bar item in a rich:panelBar. I have already read this and this and some other things on the web.

       

      I have also looked the code of RichFaces demo and its componentNavigator where there is only this simple line: <rich:panelBar style="width: auto;" selectedPanel="#{componentNavigator.currentComponent.group}" height="680px" contentStyle="background:none;">, the backing bean with a keep alive annotation and short declaration in web.xml. No a4j:support, so how does it work?

       

      I’m working with Seam. Hereunder, my simple code:

      <rich:panelBar selectedPanel="#{sidebarController.currentGroup}">
          <rich:panelBarItem id="deploiements" label="Déploiements">

          […]

          </rich:panelBarItem>

          […]

      </rich:panelBar>

       

      And the backing bean:

      @Name("sidebarController")
      @Stateful
      @Scope(ScopeType.SESSION)
      @AutoCreate
      public class SidebarControllerBean implements SidebarController {
          private static final long serialVersionUID = 7924870476939863030L;
         
          private String currentGroup = null;
         
          @Destroy
          @Remove
          public void destroy() {
          }

       

          public void setCurrentGroup(String currentGroup) {
              this.currentGroup = currentGroup;
          }

       

          public String getCurrentGroup() {
              return currentGroup;
          }
      }

       

      Doesn’t yet post on the Seam forum because I think it’s more RichFaces specific.

       

      Any idea? Thanks in advance.

        • 1. Re: rich:panelBar and selectedPanel
          ilya_shaikovsky

          if you will explore demo code more - you will see that component id always added to request parameters and getter for selectedPanel object searches for the group which contains it and return group id. So no support needed. Your code also looks ok. After any submit - selected panel id wil be placed into object and will be stiored beteween requests.

          1 of 1 people found this helpful
          • 2. Re: rich:panelBar and selectedPanel
            pomcompot

            So, I explore deeper the demo code and indeed I found the c parameter you talk about.

             

            I have succeeded in getting the right behavior with this code in the JSF:

            <a4j:form>
                <rich:panelBar style="width: auto;"
                        selectedPanel="#{sidebarController.currentGroup}"
                        height="540px"
                        contentStyle="background:none;">
                    <rich:panelBarItem id="deploiements" label="Déploiements">
                        <a4j:support event="onenter"
                                immediate="false"
                                actionListener="#{sidebarController.handleMenuChange}" />
                        […]
                    </rich:panelBarItem>
                    […]
                </rich:panelBar>
            </a4j:form>

             

            And this in my bean:

            @Name("sidebarController")
            @Stateful
            @Scope(ScopeType.SESSION)
            @AutoCreate
            public class SidebarControllerBean implements SidebarController {
                private static final long serialVersionUID = 7924870476939863030L;
               
                private String currentGroup = null;
               
                @Destroy
                @Remove
                public void destroy() {
                }

             

                public void setCurrentGroup(String currentGroup) {
                    this.currentGroup = currentGroup;
                }

             

                public String getCurrentGroup() {
                    return currentGroup;
                }
               
                public void handleMenuChange(ActionEvent event) {
                    this.currentGroup = event.getComponent().getParent().getId();
                }
            }

             

            The selectedPanel without the a4j:support call the setCurrentGroup but not with the right value. It call it with the id of the previously selected menu item, one step too late.