我是 Richfaces 框架的新手,我将在我工作中最近的项目中使用它。
我创建了一些简单的示例,其中我有 rich:dataTable 并且我正在尝试对列进行排序。我在教程(http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_column.html)中读到,我需要在“rich:column”中输入“sortBy”参数“ 标签 。不幸的是,列不能排序。有谁能够帮我?下面是我的简单应用程序的源代码:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<f:view>
<h:head></h:head>
<h:body>
<rich:panel header="Richfaces dataTable">
<rich:dataTable value="#{TaskListBean.dataList}" var="dataItem"
rows="4" columnClasses="50,100,100,100"
onRowMouseOver="this.style.backgroundColor='#B5F3FB'"
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.rowBackgroundColor}'"
width="350">
<f:facet name="caption">
<h:outputText value="This is the caption" />
</f:facet>
<f:facet name="header">
<h:outputText value="Trouble Ticket Systems" />
</f:facet>
<rich:column colspan="4">
<h:outputText value="Trouble Tickets opened" />
</rich:column>
<rich:column sortBy="#{dataItem.taskInstanceId}">
<f:facet name="header">Ticket Id</f:facet>
<h:outputText value="#{dataItem.taskInstanceId}" />
</rich:column>
<rich:column sortBy="#{dataItem.taskNode}">
<f:facet name="header">Status</f:facet>
<h:outputText value="#{dataItem.taskNode}" />
</rich:column>
<rich:column sortBy="#{dataItem.actorId}">
<f:facet name="header">Actor</f:facet>
<h:outputText value="#{dataItem.actorId}" />
</rich:column>
<rich:column>
<f:facet name="header">Description</f:facet>
<h:outputText value="#{dataItem.description}" />
</rich:column>
<f:facet name="footer">
<h:outputText value="This is the footer" />
</f:facet>
</rich:dataTable>
</rich:panel>
</h:body>
</f:view>
我的应用程序的受管理 Bean:
package richfacesr;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
@ManagedBean(name = "manager")
public class TaskListBean implements Serializable {
private ArrayList dataList;
public void loadDataList() {
dataList = new ArrayList();
TaskListData data1 = new TaskListData();
data1.setTaskInstanceId(1000l);
data1.setActorId("Willy smith");
data1.setTaskNode("In Charge");
data1.setDescription("CR 123456");
TaskListData data2 = new TaskListData();
data2.setTaskInstanceId(1001l);
data2.setActorId("Frank Sinatra");
data2.setTaskNode("Rejected");
data2.setDescription("CR 654321");
dataList.add(data1);
dataList.add(data2);
}
public List<TaskListData> getDataList() {
loadDataList();
return dataList;
}
}
和对象:
package richfacesr;
import java.util.ArrayList;
import java.util.List;
public class TaskListData {
private String taskNode;
private long taskInstanceId;
private String actorId;
private String description;
public String getActorId() {
return actorId;
}
public void setActorId(String actorId) {
this.actorId = actorId;
}
public String getTaskNode() {
return taskNode;
}
public void setTaskNode(String currentNode) {
this.taskNode = currentNode;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public long getTaskInstanceId() {
return taskInstanceId;
}
public void setTaskInstanceId(long taskInstanceId) {
this.taskInstanceId = taskInstanceId;
}
}