4 Replies Latest reply on Oct 17, 2012 3:34 AM by jifero27

    Sortable dataTable returns wrong data in rowclick listener in RichFaces 4

    jifero27

      I have a rich:dataTable component (RF 4.2.2.Final). I've added the rowclick listener for the table to update a detailed view based on the row selection. Everything was working fine. But now I'm trying to get my dataTable to have sortable headers. I follow the RF showcase and find out that the row selection doesn't work properly if the data in the dataTable isn't in natural order - it means in order in which the data is in the list in appQuery bean.

       

      E.g. if I have a list:

       

      1 code1

      2 code2

      3 code3

       

      and I click on first row I get id=1 (correct)

       

      But then I click on header and change the order:

       

      3 code3

      2 code2

      1 code1

       

      and I click on first row I get id=1 (wrong!)

       

      <h:form id="appFormId">
         
      <div>
             
      <rich:dataTable id="appListTableId" value="#{appQuery.applicationList}"
                              var
      ="row" rendered="#{!empty appQuery.applicationList}"
                              rows
      ="50" styleClass="styledTable">
                 
      <a:ajax
                     listener
      ="#{appQuery.actionListener(row.id)}"
                      event
      ="rowclick" render=":applistform:appViewId"/>
                 
      <rich:column style="width:10%">
                     
      <f:facet name="header">#{msg['ID']}</f:facet>
                     
      <h:outputText value="#{row.id}" />
                 
      </rich:column>
                 
      <rich:column style="width:20%" sortBy="#{row.code}"
                        sortOrder
      ="#{applicationSortManager.sortOrder}">
                     
      <f:facet name="header">
                         
      <a:commandLink
                              value
      ="#{msg['APPLICATION.CODE']}" render="appListTableId"
                              action
      ="#{applicationSortManager.sortByCode}" /></f:facet>
                     
      <h:outputText value="#{row.code}" />
                 
      </rich:column>
      ....................................................           

       

              </rich:dataTable>
         
      <div>
      </h:form>

       

       


      ApplicationSortManager follow the example from RF showcase. AppQuery is a simple ViewScoped component that provides the data and the listener.

       

      Do I make something wrong, or just sortable and selectable DataTable in RF4 needs some manual programming? Very similar solution works perfectly in RF 3.


        • 1. Re: Sortable dataTable returns wrong data in rowclick listener in RichFaces 4
          nick.graves

          Good morning.

           

          I ran into a similar issue with the dataTable tag.  I found a suggestion online that said to pass the whole object into the selection listener and not the row ID.  The sorting function will not rebuild the list and will retain the original structure, so your row ID will point to the orgingal row with that ID.  So, try and modify your a4j:ajax tag like so:

           

          from-

          <a:ajax
                         listener
          ="#{appQuery.actionListener(row.id)}"
                          event
          ="rowclick" render=":applistform:appViewId"/>

           

          to-

          <a:ajax
                         listener
          ="#{appQuery.actionListener(row)}"
                          event
          ="rowclick" render=":applistform:appViewId"/>

           


          Modify your listener to receive an object of type ... and then obtain your row ID etc.

           

          Let me know if that helps.

           

          Nick G.

          • 2. Re: Sortable dataTable returns wrong data in rowclick listener in RichFaces 4
            jifero27

            No. It does not change anything.

            In RF 3 almost the same functionality (with a4j:support) works OK. But I didn't find in any migration guide any information about important difference between a4j:support and a4j:ajax, that may be a reason of such problem.

            • 3. Re: Sortable dataTable returns wrong data in rowclick listener in RichFaces 4
              nick.graves

              Okay.  I reviewed some of my existing code and found that when I filter my dataTable, I was having the same issue.  One suggestion I found is to remove the a4j:ajax tag and add an a4j:outputLink tag to the first column.  The outputLink will be bound to each row and can be styled to "none".  Here is a copy of my code:

               

              <rich:dataTable value="#{tempController.items}" var="item" id="tempConfigTable" rows="10" style="text-align: center;">

                 <rich:column style="width:200px" filterValue="#{tempController.fromMemberFilter}" filterExpression="#{fn:containsIgnoreCase(item.frommember,tempController.fromMemberFilter)}">

                     <f:facet name="header">

                         <h:panelGroup>

                             <h:outputText value="from member"/>

                             <text> </text>

                             <h:inputText value="#{tempController.fromMemberFilter}" label="From Member">

                                 <a4j:ajax event="blur" render=":tempConfigTable :tempConfigTableDataScroller" execute="@this" />

                             </h:inputText>

                         </h:panelGroup>

                     </f:facet>   

                     <h:outputText value="#{item.frommember}"/>

                                  <!-- the hidden command link below will replace the "rowclick" functionality and pass the correct object to your listener -->

                          <a4j:commandLink value="select" action="#{tempController.selectionListener(item)}"

                                      execute="@this" render=":detailForm:detailPanel" style="display:none !important;" styleClass="selLink"/>

                 </rich:column> 

               

              Listener code:

               

              public void selectionListener(TempConfigClass itemObject) {

                      setSelectedTempConfig(itemObject);      

                 }

               

              The hidden command link may help you.  I will try to find the original blog entry etc. that helped me find my solution.

               

              Nick G.

              1 of 1 people found this helpful
              • 4. Re: Sortable dataTable returns wrong data in rowclick listener in RichFaces 4
                jifero27

                Thank you very much, Nick. Your solution works.

                 

                The other is server side sorting - if I re-sort the source list  (appQuery.applicationList)in managed bean, everything is working fine with a4j:ajax too.

                 

                It seems however that there's a problem with a4j:ajax and f:ajax and client side sorting in dataTable. The question is: it is a bug in rich:dataTable or f:ajax?

                 

                Maybe someone can explain the reason of the behaviour?