4 Replies Latest reply on Jun 28, 2010 2:11 PM by ayven

    Problem with sort column links in rich:dataTable after rerendering

    ayven

      Scenario description:

      --------------------------------

      I would like to display a 'rich:dataTable' with sorting functionality on a page after clicking on 'a4j:commandButton' (table will be rendered in 'ajax' way).

      Here is a snippet of XHTML code (complete '.xhtml' file is included as attachment):

       

      <h:form>
      <a4j:commandButton id="cmdButton" value="click" reRender="tablePanel" action="#{legalEntitySearchAction.exampleAction}" />
      </h:form>
      <a4j:outputPanel id="tablePanel">
      <h:form id="tableForm">
      <rich:dataTable id="table" value="#{legalEntitySearchAction.exampleList}" var="value" rows="10"
      rendered="#{legalEntitySearchAction.exampleList.size > 0}">
      <rich:column sortBy="#{value}" width="100px">
      <f:facet name="header">
      <h:outputText value="value" />
      </f:facet>
      <h:outputText value="#{value}" />
      </rich:column>
      </rich:dataTable>
      </h:form>
      </a4j:outputPanel>
      
      
      Command button invokes ajax action (legalEntitySearchAction.exampleAction), which fills sample ArrayList (legalEntitySearchAction.exampleList) with example string values. These values are listed in "rich:datable", which is rendered only if the list is not empty and it shall provide also column sorting functionality. Any additional page actions are not defined in '.page.xml' file.
      Below is shown source code of Stateful EJB bean, which handles exampleAction and creates exampleList:

      @Stateful
      @Name("legalEntitySearchAction")
      @Scope(ScopeType.CONVERSATION)
      public class LegalEntitySearchActionBean implements LegalEntitySearchAction {
      
          private List<String> exampleList = new ArrayList<String>();
      
          public List<String> getExampleList() {
           return exampleList;
          }
      
          public void setExampleList(List<String> exampleList) {
           this.exampleList = exampleList;
          }
      
          public List<String> exampleAction() {
      
           for (int i = 0; i < 10; i++) {
               if (i % 2 == 0) {
                exampleList.add("abcd");
               } else {
                exampleList.add("efgh");
               }
           }
      
           return exampleList;
          }
      
      }
      

       

       

      Problem:

      -----------

      After clicking on command button, the table is rendered on the page with correct values, but:

      After clicking on sort link in column header, values are not sorted and table is not re-rendered at all (also images - arrows in column header are not changed). I notice that ajax request is sent after clicking on sort link and also response is received, but it does not contain any HTML code with 'table' elements (a4j:log component output is included as attachment). This operation also does not produce any Java Script error or any JSF error messages.

      I notice also that if the table is rendered on the page immediately after GET request and then the table is again re-rendered by AJAX request, sort links work fine. The problem appears only if the table is not displayed after first GET request on a page and subsequently rendered by AJAX.

      I also tried to re-render only parent form (instead of 'a4j:outputPanel'), but the result is same.

       

      Can someone pls help me with this?

      Thanks in advance.

       

      Environment:

      ------------------

      Seam 2.2.0.GA

      RichFaces 3.3.3.Final

      Facelets 1.1.14

      JSF 1.2 (shipped with Weblogic 10.3.2)

      Application is deployed on Weblogic 10.3.2 as EAR.

      Tested with Firefox 3.6.3 and Chromium 6.0.

        • 1. Re: Problem with sort column links in rich:dataTable after rerendering
          ilya_shaikovsky

          the problem in

           rendered="#{legalEntitySearchAction.exampleList.size > 0}"

          and the solution is in using session scope or to start long running conversation(currently you lack's @begin method so conversation created for every request from cratch).

          and the description is there:

          http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering

          • 2. Re: Problem with sort column links in rich:dataTable after rerendering
            ayven

            Thanks, you are right. I've finally got it working.

            Actually, I previously tried to change also the scope of the EJB bean and even if the bean had 'session' scope, it still didn't work. There was another problem: I placed the 'rich:dataTable' element in nested form ('a4j:command' button was in a parent form), so it looked like this:

             

            <h:form>
                 <a4j:commandButton id="cmdButton" value="click" reRender="tablePanel" action="#{legalEntitySearchAction.exampleAction}" />
                 
                 <a4j:outputPanel id="tablePanel">
                     
                  <h:form id="tableForm">
                           <rich:dataTable id="table" value="#{legalEntitySearchAction.exampleList}" var="value" rows="10"
                           rendered="#{legalEntitySearchAction.exampleList.size > 0}">
                                <rich:column sortBy="#{value}" width="100px">
                                     <f:facet name="header">
                                          <h:outputText value="value" />
                                     </f:facet>
                                     <h:outputText value="#{value}" />
                                </rich:column>
                           </rich:dataTable>
                   </h:form>
            
                 </a4j:outputPanel>
            
            
            </h:form>
            
            

             

            If I use one form for all elements (action button and table) or separate forms for button and table in combination with session scoped EJB, it works fine. But in case of use a nested form (as shown above) with session scoped EJB, the sort link does not work. I noticed that in this case, a new instance of 'exampleList' (and EJB bean) is created each time I click on a sort link and table is re-rendered.

            Could you please explain me, why does it behave like this?

             

            Thanks.

            • 3. Re: Problem with sort column links in rich:dataTable after rerendering
              ilya_shaikovsky

              nested forms just not allowed in JSF.

              • 4. Re: Problem with sort column links in rich:dataTable after rerendering
                ayven

                Thanks for explanation.