RichFaces built-in sorting

Sorting data in a table is a common task. Luckily, RichFaces comes out-of-the-box with basic sorting. To make it a little bit more interesting I will use 7 New Wonders of the World data from Wikipedia instead of plain User or Account data. All images are linked from Wikipedia as well.

In this post I will show in-table sorting or by clicking the column header. In the next post I will show how to sort via external controls (buttons outside the table).

First, here is my managed bean:

package wonder;

import java.util.ArrayList;
import javax.annotation.PostConstruct;

public class NewWondersBean {

   private ArrayList  sevenNewWonders = new ArrayList ();

   public void init () {
	sevenNewWonders = new ArrayList ();
	sevenNewWonders.add(new Wonder("Chichen Itza", "Mexico", ""));
	sevenNewWonders.add(new Wonder("Christ the Redeemer", "Brazil", ""));
	sevenNewWonders.add(new Wonder("Colosseum", "Italy", ""));
	sevenNewWonders.add(new Wonder("Great Wall of China", "China", ""));
	sevenNewWonders.add(new Wonder("Machu Picchu", "Peru", ""));
	sevenNewWonders.add(new Wonder("Petra", "Jordan", ""));
	sevenNewWonders.add(new Wonder("Taj Mahal", "India", ""));

   public ArrayList  getSevenNewWonders() {
	return sevenNewWonders;

Wonder class has three properties, all strings (name, location, imageUrl).

This is how the JSF page looks:


To get the sorting working, all you need to do is specify sortBy attribute on rich:column. sortBy is an expression that points to a property in the bean to be sorted by. That’s it. Here is how it looks. Notice the arrows (up/down) in the header. You click them to sort.


5 thoughts on “RichFaces built-in sorting

  1. class org.richfaces.component.html.HtmlDataTable (id=”xx”) did not find parent form.

    The error is solved by putting the dataTables in

    so final code is


Leave a Reply to ahmet Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.