0

Versions :

Aapche MyFaces 2.1.14 RichFaces 4.3.5

Code :

<rich:dataTable var="row" value="#{bean.rowData}"  index="dataIndex">

        <rich:columns value="#{bean.columnData}" var="column" index="ind" sortBy="#{row[column.id].sort}" sortOrder="#{bean.sortOrder[column.id]}">
            <f:facet name="header">
                <h:outputText value="#{column.header}" />
            </f:facet>          
        #{row.value}
        </rich:columns>                 
</rich:dataTable>

Issue :

We are migrating from JSF 1.2 to JSF 2. As shown in below code snippet , we were using <rich:columns> to dynamically generate columns and to add sort feature for the columns. Since <rich:columns> is now removed , we need to use <c:forEach> to generate dynamic columns as per Dynamic columns with richfaces 4

But the issue remains is how to add sort behaviour for the columns.

Is there any alternative available ?

Please help.

EDIT 1 :

I am able to get the desired behaviour by below code , as stated in the comments for the question.

<rich:extendedDataTable id="masterTable" var="row" value="#{bean.rowData}"  index="dataIndex" render="masterTable">       
    <c:forEach items="#{bean.columnData}" var="column">                     
        <rich:column sortBy="#{row[column.id].sort}" sortOrder="#{bean.sortOrder[column.id]}"> 
                    <f:facet name="header">
                        <h:outputText value="#{column.header}" />
                    </f:facet>          
                    #{row.value}
            </rich:column>
    </c:forEach>               
</rich:extendedDataTable>

The reason for using <rich:extendedDataTable> is , it allows built-in sorting with arrows (for sorting order displaying). The above set up is working. The issue is now , after I click on column header for sorting ,ajax reRendering doesn't seem to work. It requires manual page refresh and then sorted data is shown on the page. I have observed same issue earlier at other place with <c:forEach> . When I removed <c:forEach> with <rich:dataGrid> , it worked. But in this case as per post Dynamic columns with richfaces 4, I have to stick with <c:forEach>

EDI 2 : The ajax rendering issue is observed when sorting is applied to another column than present one . After page is refreshed , sorting for that particular column works fine until another column is applied for sort.

Community
  • 1
  • 1
Atul
  • 1,560
  • 5
  • 30
  • 75
  • Is there a problem using sortBy of rich:column? Same as here (only the difference you would use c:forEach with rich:column inside): http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=dataTable&sample=tableSorting&skin=blueSky – Andrey Feb 06 '14 at 19:19
  • See [this answer](http://stackoverflow.com/questions/9971651/how-to-sort-a-column-in-a-datatable-jsf-2-0/19386833#19386833). It may help. – Vasil Lukach Feb 06 '14 at 21:15
  • @Andrey,@Vasil : Thanks for your inputs . I am able to progress a little bit. I have updated my question accordingly. The issue of rendering still exists – Atul Feb 07 '14 at 09:06
  • @VasilLukach : As per your answer on question http://stackoverflow.com/questions/9971651/how-to-sort-a-column-in-a-datatable-jsf-2-0/19386833#19386833 , how can I add two arrows for sorting if is used for sorting – Atul Feb 07 '14 at 11:00
  • 1
    Like this: ` ` – Vasil Lukach Feb 07 '14 at 15:44
  • 1
    Sorry it is not enough space for full code of `rich:column`. Idea is use 3 images for 1) sort asc, 2) sort desc, 3) unsort and render it or using EL for build `value` attribute of image based on needed sorting. – Vasil Lukach Feb 07 '14 at 15:48

0 Answers0