0

我必须显示Student表中的数据<p:dataTable>,如下所示:

<p:dataTable
    value="#{school.getStudent(GENDER)}"
    var="student" />
    ......all <p:columns>
</p:dataTable>

在这里,school.getStudent(MALE)将返回所有男学生school.getStudent(FEMALE)的列表,并将返回所有女学生的列表。

现在我面临的问题是订购数据。要求是:

  • 如果是MALE,则根据ID
  • 如果是FEMALE,则根据NAME

ID并且NAME是表格的列Student

我怎样才能做到这一点?

4

2 回答 2

3

在你的支持 bean 中执行此操作。在归还之前对要显示的收藏进行排序。Primefaces 将按照 Collection 提供条目的顺序显示表中的条目。所以使用 anArrayList来保持顺序并使用 Comparator withCollections.sort(...)来对 List 进行排序。

可能看起来像这样:

public List<Student> getStudent(Gender gender) {
    Comparator<Student> comparator;
    if (gender == Gender.MALE) {
        comparator = new MaleStudentComparator();
    }
    else {
        comparator = new FemaleStudentComparator();
    }

    return Collections.sort(studentList, comparator);
}
于 2013-08-22T09:48:21.860 回答
0
  <p:column sortBy=#{bean.gender ? widgetVar.Name : widgetVar.id}>

假设 bean.gender 是一个布尔值,在女性的情况下返回“True”,在“男性”的情况下返回“False”。

于 2013-08-22T10:07:13.867 回答