2 Replies Latest reply on Apr 24, 2008 4:28 PM by Amir Shay

    rich:panelBar save state (selectedPanel)

    Alan Newbie

      I have a problem saving the state of the panelBar component. I like to have the same panelBarItem opened between request.

      The following code shows my problem.

      A fragment of my page containing the panelBar component.

      <a4j:form>
       <rich:panelBar selectedPanel="#{menuState.selectedPanelBar}" valueChangeListener="#{menuState.panelBarChanged}">
       <a4j:support event="onclick" />
       <rich:panelBarItem name="fooPanel">
       Foo
       </rich:panelBarItem>
       <rich:panelBarItem name="barPanel">
       Bar
       </rich:panelBarItem>
       </rich:panelBar>
      </a4j:form>
      


      A session scoped bean to remember the selectPanelBar
      @Name("menuState")
      @Scope(value = ScopeType.SESSION)
      public class MenuState implements Serializable {
      
       @Logger
       private Log log;
      
       @In
       private FacesContext facesContext;
      
       private String selectedPanelBar = "barPanel";
      
       public void panelBarChanged(final ValueChangeEvent evt) {
       log.debug("Got a value changed event, new value: #0, old value #1", evt.getNewValue(), evt.getOldValue());
      
       UIPanelBarItem barItem =
       (UIPanelBarItem) facesContext.getViewRoot().findComponent(evt.getNewValue().toString());
       UIPanelBar panelBar = barItem.getPanel();
      
       log.debug("selected panelBar: #0", panelBar.getSelectedPanel());
       log.debug("submittedValue #0", panelBar.getSubmittedValue());
       log.debug("value: #0", panelBar.getValue());
       String name = (String) barItem.getName();
       log.debug("name: #0", name);
       }
      
       public String getSelectedPanelBar() {
       return selectedPanelBar;
       }
      
       public void setSelectedPanelBar(final String selectedPanelBar) {
       this.selectedPanelBar = selectedPanelBar;
       }
      }
      


      The result of running this code is that intial the barPanel is opened, as expected. When the user clicks on the fooPanel the panel is opened but the new value of the valueChanged event is the previous panel and the old value is null.

      First the setter is called with the previous selectedTabPanel name. Thus: barPanel. After that the valueChangeListener. The resulting name is also the previous tab before the user selected a new tab.

      Can somebody explain this? Is there another way to keep hold of the selectedPanel?

      I am using Richfaces 3.1.4, Jboss 4.2.0 and SEAM 1.2.1

        • 1. Re: rich:panelBar save state (selectedPanel)
          Alan Newbie

          I think the cause of my problem is that the switchType of the component is client.
          The Ajax request that should update the menuState bean is fired after the panel has changed (this is client side switch type). Now the selected value (save as hidden input in the form) is not updated before the ajax request is fired I think. So the values the valueChangeLister gets are old.

          When does the panelBar support client or ajax switchType.

          Maybe I should use a different event of my a4j:support so that the ajax request get fired after the client as updated its values.

          • 2. Re: rich:panelBar save state (selectedPanel)
            Amir Shay Newbie

            To whom is may help

            After investigating the problem of getting the selected tab I found that probably the valueChangeListener of the rich:panelBar is not working. My workaround is

            In the facelet

            <a4j:form>
             <rich:panelBar selectedPanel="#{menuState.selectedPanelBar}" >
             <rich:panelBarItem name="fooPanel" id="fooPanel">
             <a:support event="onenter" immediate="false" actionListener="#{menuState.panelBarChanged}" />
             Foo
             </rich:panelBarItem>
             <rich:panelBarItem name="barPanel" id="barPanel">
             <a:support event="onenter" immediate="false" actionListener="#{ menuState.panelBarChanged }" />
             Bar
             </rich:panelBarItem>
             </rich:panelBar>
            </a4j:form>
            
            



            And the java listener function is

            public void panelBarChanged(ActionEvent evt) {
             appPanel = evt.getComponent().getParent().getId();
            
             }