Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

datatable with sorting in jsf  RSS feed

 
baabs
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement the data table with sorting in JSF.
please anybody can help me.


by
Babu
 
Oles Slezka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)You can use datatable from myfaces table
sort header
2)Implement in bean method for defining name column and for sorting kind like
Collections.sort(list, Comparator);
 
CareBear
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geary-Horstmann corejsf book has an example. They used the approach of implementing a SortFilterModel extends DataModel. Within the class, they created a sortby method with the flavored comparator.

Here is a snippet:

<h:dataTable value="#{filteredTableData.names}" var="name"
styleClass="names" headerClass="namesHeader"
columnClasses="last,first">
<h:column>
<f:facet name="header">
<h:commandLink action="#{filteredTableData.names.sortByLast}">
<hutputText value="last"/>
</h:commandLink>
</f:facet>
<hutputText value="#{name.last}"/>
<f:verbatim>,</f:verbatim>
</h:column>
 
CareBear
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, the src code comes with the book might need modification to get it work. Here is my own version:

public String sortByFirst() {

Name[] names = (Name[])model.getWrappedData();
Arrays.sort(names, byFirst);
return null;
}

and here is my sort comparator:

private static Comparator byFirst = new
Comparator() {
public int compare(Object o1, Object o2) {
Name n1 = (Name) o1;
Name n2 = (Name) o2;
return n1.getFirst().compareTo(n2.getFirst());
}
};
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"KS KS",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!