1 Reply Latest reply on Jun 10, 2009 3:18 AM by Nick Belaevski

    a4j:keepAlive & rich:tabPanel

    Philipp Berger Newbie

      Hi,

      I am trying to use a rich:tabPanel within a form. The backing bean holding form data is in request scope and kept alive with a4j:keepAlive.

      Here a simplified example:



      <a4j:keepAlive beanName="personBean" />
      
      <a4j:form>
       <rich:tabPanel switchType="ajax"
       selectedTab="#{personBean.selectedTab}">
       <rich:tab id="tab1" label="firstname">
       <a4j:region>
       <h:inputText value="#{personBean.firstname}" />
       </a4j:region>
       </rich:tab>
       <rich:tab id="tab2" label="lastname">
       <a4j:region>
       <h:inputText value="#{personBean.lastname}" />
       </a4j:region>
       </rich:tab>
       </rich:tabPanel>
      </a4j:form>


      The selectedTab attribute is mapped to the backing bean by a value expression in order to be able to control the first opened tab when the page loads.

      Now, when i insert some text in the first inputText on the first tab and click on the second tab, personBean.firstname gets updated, but not if i enter something on the second tab and click on the first.

      While debugging I found that during phase 1 the tabPanel evaluates the value expression for the selectedTab- attribute using a new instance of the backing bean instead of the instance being kept-alive by the a4j:keepAlive. In phase 4 however the tabPanel does not re-evaluate the value expression and uses the value previously evaluated in Restore View Phase. I assume this causes in the wrong components being considered to be updated to the model in the backing bean.

      When I change line 55 in http://fisheye.jboss.org/browse/RichFaces/branches/community/3.3.X/ui/tabPanel/src/main/java/org/richfaces/component/UITabPanel.java?r=12379#l55 from
      final Object renderedValue = this.restoredRenderedValue;

      to
      final Object renderedValue = getRenderedValue();
      (which by the way does not seem break any unit tests) the model gets updated correctly when changing tabs in both direction, because the right instance of the backing bean is used for (re-)evaluating the selectedTab- attribute.

      Might this be a bug in UITabPanel (or maybe in a4j:keepAlive because evaluating selectedTab creates a new BackingBean in Phase1)?

      Thanks,

      Philipp