8 Replies Latest reply on Feb 17, 2011 1:58 AM by darcyg

    Sortorder in column sorting of extendedDataTable in Richfaces 4 M5

    darcyg

      Hi to everybody,

       

      I'm new to JSF and especially to RichFaces. My Environment is Eclips Galileo-SR2-Bundle, Richfaces 4 M5 and Tomcat 6.

       

      I'm trying extendedDataTable with column sorting. I have refered demo: 

      http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?sample=tableSorting&demo=dataTable&skin=blueSky

       

      In the demo, for sorting a column, they have used the following code.

       

      <rich:column sortBy="#{cap.name}" id="name"

                      sortOrder="#{capitalsSortingBean.capitalsOrder}">

                      <f:facet name="header">

                          <a4j:commandLink value="Sort by Capital Name" render="table"

                              action="#{capitalsSortingBean.sortByCapitals}" />

                      </f:facet>

                      <h:outputText value="#{cap.name}" />

      </rich:column>

       

       

      sortOrder is changed using "capitalsSortingBean.capitalsOrder".

       

      Suppose if I have 10 columns to sort, then from the above example what i understood was to create a bean with all those 10  sortorder attributes to be sorted. and write methods to change the sort order. Can't we do some thing like, if first time it is sorted in Ascending order, then when i clicked on column header to sort, it should sort the column in the descending order. with out creating a bean with methods to handle the  changing the sort order. 

       

      Is it possible in Richfaces 4 M5?.

       

      Thanks in advance....

        • 1. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
          konstantin.mishin

          Hi Darcy.

           

          You could use # {rich:component('tableId')}.sort('columnId', ['sortOrder']) JS api.

          It should be in your case something like this:

          <rich:column sortBy="#{cap.name}" id="name" sortOrder="ascending">

               <f:facet name="header">

                    <a onclick="# {rich:component('tableId')}.sort('name');return false" href="#">Sort by Capital Name</a>      

               </f:facet>

               <h:outputText value="#{cap.name}" />

          </rich:column>

          • 2. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
            darcyg

            Hi Konstantin,

             

                  Thanks for you fast reply. I tried what you have said.But it is not working. If we give sortOrder="ascending", it is always in ascending order. when I clicked on the column header, it is not changeing to descending.....

             

            I'm using rich:extendedDataTable.

             

            <rich:extendedDataTable id="tableId" value="#{testDataModel}"

                                        var="testEntity" sortMode="single" rows="#{formObject.pageSize}"

                                        reRender="datascroller">

             

                                     <rich:column id="name" label="Name" width="200"

                                            sortBy="#{name}" sortOrder="ascending"

                                            selfSorted="false" >

                                            <f:facet name="header">

                                                    <a onclick="# {rich:component('tableId')}.sort('name');return false" href="#">Name</a>    

                               

                                            </f:facet>

                                            <h:outputText value="#{testEntity.name}" />

                                        </rich:column>

                </rich:extendedDataTable>

            • 3. Re: Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
              konstantin.mishin

              I have added to:

              http://www.richfaces-showcase.appspot.com/richfaces/component-sample.jsf;jsessionid=hm0HRA8E6N_5dH6a5c-dng?demo=extendedDataTable

              next code:

              <rich:column id="model" sortBy="#{car.model}" sortOrder="ascending">

                              <f:facet name="header">

                                  <a onclick="#{rich:component('table')}.sort('model');return false" href="#">Model</a>

                              </f:facet>

                              <h:outputText value="#{car.model}" />

                          </rich:column>

              Sorting is working without problems.

              • 4. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
                darcyg

                Hi Konstantin,

                 

                   We are using extendedDataTable with lazy model(we are extending SerializableDataModel.class and implementing Arrangeable class),

                 

                While debugging we found out that in the JSF Phase ' APPLY_REQUEST_VALUES' - sortorder is descending. The sortorder is descending till JSF Phase- 'RENDER_RESPONSE' .

                 

                and in the JSF Phase: RENDER_RESPONSE - 6.-  extendedDataModel is set to null in UIDataAdaptor.class in resetDataModel() method.It will create extendedDataModel again after that . So it will invoke arrange method again. In that sortOrder is descending  so it will change to ascending. That's why it is always in ascending order

                • 5. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
                  konstantin.mishin

                  Hi Darcy.

                   

                     While debugging we found out that in the JSF Phase ' APPLY_REQUEST_VALUES' - sortorder is descending. The sortorder is descending till JSF Phase- 'RENDER_RESPONSE'

                  Do you mean value of attribute "sortorder" of rich:column or some fields of your model or something else?

                  In that sortOrder is descending  so it will change to ascending.

                  Clarify this sentence please.

                  • 6. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
                    darcyg

                    Hi Konstantin,

                     

                               Yes, the "sortorder" is the attribute of the rich:column.

                    Initial value of the sortorder is ascending. When we click on the column for sorting, the request goes through JSF Lifecycle.

                     

                    In JSF Phase ' APPLY_REQUEST_VALUES' - sortorder is changed to descending and in the phase 'RENDER_RESPONSE'., the sortorder is changed back to the ascending.

                    • 7. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
                      konstantin.mishin

                      Hi Darcy.

                      ... and in the phase 'RENDER_RESPONSE'., the sortorder is changed back to the ascending.

                      It shouldn't be. I have never seen this in any our samples.

                      I suggest you to do the following:

                      1. try to map sortOrder in some bean
                      2. compare your code with our one from richfaces-showcase (in this project the sorting is working without problems)
                      3. create an issue in our jira, if the previous points were unsuccessful. Attach the sample project which we can run to this issue.
                      • 8. Sortorder in column sorting of extendedDataTable in Richfaces 4 M5
                        darcyg

                        Hi Konstantin,

                         

                              With bean it is working .As I menation in my post, the showcase  http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?sample=tableSorting&demo=dataTable&skin=blueSky

                         

                        is also using a bean..But we want a generic approch.........