DataTable列 - 按selectItems itemLabel过滤?

时间:2017-07-31 19:31:38

标签: java jsf primefaces

我已经尝试过研究这个并解决问题,所以我已经达到了要求:

<p:column headerText="ProjectStatusCode" filter=?? filterMatchMode=?? >
    <p:selectOneMenu value="#{person.statusCodeIDForProject}">
        <f:selectItem itemLabel="None" 
                      itemvalue= "-1"/>
        <f:selectItems value="#{backingBean.allStatusCodes}" 
                       var="c" 
                       itemLabel="#{c.statusCodeName}" 
                       itemValue="#{c.statusCodeID}"/>
        <p:ajax listener="#{backingBean.editStatusCodeForProject(person.personID, person.statusCodeIDForProject)}"/>
    </p:selectOneMenu> 
</p:column>

理想情况下,我想通过itemLabel(在本例中为statusName)过滤列。状态名称对前端用户的价值高于ID。

修改

这是主要的3.5.8

1 个答案:

答案 0 :(得分:0)

试试这个

facelets页面:

        <p:dataTable var="bb" value="#{backingBean.dataList}" widgetVar="dataTable"
                     emptyMessage="No item found with given criteria">
            <p:column filterBy="#{bb.status}" headerText="list header" footerText="exact" filterMatchMode="exact">
                <f:facet name="filter">
                    <h:selectOneMenu onchange="PF('carsTable').filter()" >
                        <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
                        <f:selectItems value="#{backingBean.statusList}"/>
                    </h:selectOneMenu>
                </f:facet>
                <h:outputText value="#{bb.status}" />
            </p:column>
        </p:dataTable>

这里的诀窍是让你的StatusCodetoString()返回just statusName

public class StatusClass {

    String statusName;
    int statusCode;

    public StatusClass() {
    }

    StatusClass(String name, int i) {
        this.statusName = name;
        this.statusCode = i;
    }

    public String getStatusName() {
        return statusName;
    }

    public void setStatusName(String statusName) {
        this.statusName = statusName;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }


    //return just the status name
    @Override
    public String toString() {
        return "" + statusName;
    }

}

并在你的BackingBean中

private ArrayList<DataClass> dataList;//points to your dataTable value
private ArrayList<StatusClass> statusList;//points to your statusList for selectOneMenu

我希望这有帮助