简体   繁体   English

丰富:无法解决列排序

[英]rich:column sorting can't be resolved

I'm new in Richfaces framework which I'm going to use in the nearest project in my job. 我是Richfaces框架的新手,我将在我工作中的最近项目中使用它。

I've created some simple example in which I have rich:dataTable and I'm trying to make column sorted. 我创建了一个简单的示例,其中有rich:dataTable,并且试图对列进行排序。 I've read in the tutorial ( http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_column.html ) that everything what I need is to type "sortBy" parameter to the "rich:column" tag . 我已经在本教程( http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_column.html )中阅读到,我所需要的一切都是在“ rich:column”上键入“ sortBy”参数“ 标签 。 Unfortunately columns can't be sort. 不幸的是,列无法排序。 Can anybody help me? 有谁能够帮助我? Below source code of my simple app : 下面是我的简单应用程序的源代码:

<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>

Menaged Bean of my app: 我的应用程式的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;
    }

 }

and the object: 和对象:

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;
  }
}

Taken from the Richfaces 4 documentation , built in sorting for dataTables does not work. 摘自Richfaces 4文档 ,无法对dataTables进行排序。

The built-in sort controls are only available with the extendedDataTable component. 内置的排序控件仅可与ExtendedDataTable组件一起使用。 Support for built-in sort controls in the dataTable component will be added in a subsequent release. 在后续版本中将添加对dataTable组件中内置排序控件的支持。

It did work in Richfaces 3 , but it seems that they have changed a bit, so that this feature is currently not working in Richfaces 4, out of the box. 它确实可以在Richfaces 3中使用 ,但是似乎它们做了一些更改,因此该功能当前在Richfaces 4中不可用。

Although you say that you use Richfaces 5, which is Alpha1, I doubt that this feature is already in there. 尽管您说使用的是Richphas 5(Alpha1),但我怀疑该功能已经存在。 So you will need to write some code for yourself. 因此,您将需要自己编写一些代码。

Looking a the Richfaces 4 showcase about table sorting you need to 查看Richfaces 4展示的有关表格排序的展示

  • put your managed bean into ViewScope - otherwise the unsorted list will be created again and again 将您的托管bean放入ViewScope-否则将一次又一次创建未排序的列表
  • move your loadDataList out of getDataList() into the constuctor or annotate it with @PostConstruct - otherwise the unsorted list will be created again and again 将您的loadDataListgetDataList()移出到构造函数中,或使用@PostConstruct对其进行注释-否则将一次又一次创建未排序的列表
  • make your TaskListData Serializable 使您的TaskListData序列化
  • add a sort method to your TaskListBean - do the sorting there - maybe as described in Sort ArrayList of custom Objects by property 向您的TaskListBean添加排序方法-在此处进行排序-可能如按属性对自定义对象排序ArrayList中所述
  • check the name of your ManagedBean TaskListBean - in the code you call it manager , but in your xhtml you call it TaskListBean 检查ManagedBean TaskListBeanname -在您称为manager的代码中,但在xhtml中,将其称为TaskListBean

Here is my tuned version of your xhtml 这是我的xhtml的调整版本

<f:view>
    <h:head />
    <h:body>
        <h:form>
            <rich:dataTable id="table" var="dataItem"
                value="#{manager.dataList}" width="350">

                <rich:column id="ticketId" sortBy="#{dataItem.taskInstanceId}">
                    <f:facet name="header">
                        <a4j:commandLink value="Ticket Id" render="table"
                            action="#{manager.sortBy('Ticket Id')}" />
                    </f:facet>
                    <h:outputText value="#{dataItem.taskInstanceId}" />
                </rich:column>

                <rich:column sortBy="#{dataItem.taskNode}">
                    <f:facet name="header">
                        <a4j:commandLink value="Status" render="table"
                            action="#{manager.sortBy('Status')}" />
                    </f:facet>
                    <h:outputText value="#{dataItem.taskNode}" />
                </rich:column>

                <rich:column sortBy="#{dataItem.actorId}">
                    <f:facet name="header">
                        <a4j:commandLink value="Actor" render="table"
                            action="#{manager.sortBy('Actor')}" />
                    </f:facet>
                    <h:outputText value="#{dataItem.actorId}" />
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <a4j:commandLink value="Description" render="table"
                            action="#{manager.sortBy('Description')}" />
                    </f:facet>
                    <h:outputText value="#{dataItem.description}" />
                </rich:column>

            </rich:dataTable>
        </h:form>
    </h:body>
</f:view>

My tuned version of your TaskListBean 我的TaskListBean的调整版本

import java.io.Serializable;
import java.util.*;

import javax.annotation.PostConstruct;
import javax.faces.bean.*;

@ViewScoped
@ManagedBean(name="manager")
public class TaskListBean implements Serializable {

    private ArrayList<TaskListData> dataList;

    @PostConstruct
    public void loadDataList() {
        dataList = new ArrayList<TaskListData>();

        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 void sortBy(String aColumn) {
        System.out.println("sort by: " + aColumn);
        // TODO sort the list by that attribute
    }

    public List<TaskListData> getDataList() {
        return dataList;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM