<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head>
<meta http-equiv="Content-Type" content="text/html" />
<title>SEPARATOR</title>
</head>
<body>
<f:view>
<h:form>
<rich:dataTable id="table" value="#{itemList.items}" var="row"
rows="15">
<rich:columns value="#{itemList.columns}" var="column" index="i"
sortBy="#{row[column]}" id="column#{i}" sortOrder="#{itemList.sortOrder[column]}">
<f:facet name="header">
<h:outputText value="#{column}" />
</f:facet>
<h:outputText value="#{row[column]}" />
</rich:columns>
</rich:dataTable>
</h:form>
</f:view>
</body>
</html>
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class ItemList {
private String[] columns = {"name", "uuid"};
private Map<String, Object> sortOrder = new HashMap<String, Object>();
public Map<String, Object> getSortOrder() {
return sortOrder;
}
private List<Item> items;
public ItemList() {
items = new ArrayList<Item>();
for (int i = 0; i < 30; i++) {
Item item = new Item();
item.setName("Name " + i);
item.setUuid(UUID.randomUUID().toString());
items.add(item);
}
}
public List<Item> getItems() {
return items;
}
public void checkAll() {
for (Item item : items) {
item.setFlag(true);
}
}
public void uncheckAll() {
for (Item item : items) {
item.setFlag(false);
}
}
public String[] getColumns() {
return columns;
}
}
public class Item {
private boolean flag;
private String name;
private String uuid;
/**
* @return the uuid
*/
public String getUuid() {
return uuid;
}
/**
* @param uuid the uuid to set
*/
public void setUuid(String uuid) {
this.uuid = uuid;
}
/**
* @return the flag
*/
public boolean isFlag() {
return flag;
}
/**
* @param flag the flag to set
*/
public void setFlag(boolean flag) {
this.flag = flag;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
}
private Map<String, Object> sortOrder = new HashMap<String, Object>();
...
for(...) {
sortOrder.put(columnName, Ordering.UNSORTED);
}