primefaces p:按字符串列表排序的列

primefaces p:按字符串列表排序的列,primefaces,columnsorting,Primefaces,Columnsorting,当p:dataTable循环对象列表时,通过使用对象的属性,在p:column中使用SortBy方法非常容易。像这样: <p:dataTable var="o" value="#{bean.theObjectList}"> <p:column headerText="herderText" sortBy="#{o.objectAttribute1}"> <h:outputLabel value="#{o.objectAttribute1}"

当p:dataTable循环对象列表时,通过使用对象的属性,在
p:column
中使用
SortBy
方法非常容易。像这样:

<p:dataTable var="o" value="#{bean.theObjectList}">
    <p:column headerText="herderText" sortBy="#{o.objectAttribute1}">
        <h:outputLabel value="#{o.objectAttribute1}" />
    </p:column>
</p:dataTable>

public class Bean {
    private List<TheObject> objectList;

    public class TheObject {
        private String objectAttribute1;

        ...
    }

    ...
}

稍微改进了格式。为什么?通常我们在表中不只有一列
<p:dataTable var="o" value="#{bean.stringList}">
    <p:column headerText="herderText" sortBy="?">
        <h:outputLabel value="#{o}" />
    </p:column>
</p:dataTable>

public class Bean {
    private List<String> stringList;

    ...
}