数据表列中的自动完成过滤器,主要表面

时间:2014-09-17 22:45:33

标签: jsf-2 primefaces datatable

我试图以某种方式添加到datable的列中,过滤自动完成功能。我创建了Set with LastNames of clients,也在我的Bean中创建了带有getter + setter的String文本字段,但是不知道如何将它添加到过滤器中。你能帮帮我吗??

Bean中的

private Set<String> lastNames = new HashSet<String>(); //for autocomplite
private String text; //for autocomplite

的dataTable

<p:dataTable id="table" value="#{clientsListBean.clientList}" var="item" style="width:95%" styleClass="dataTable"
            sortMode="multiple" paginator="true" rows="20"  editable="true" sortOrder="descending" 
            draggableColumns="true" emptyMessage="No clients found with given search criteria"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >


        <p:column headerText="Last Name" filterBy="last_name" sortBy="last_name" style="width:auto; text-align:center" for="autocompl" > 
                <p:autoComplete id="autocompl" value="#{clientsListBean.text}" completeMethod="#{clientsListBean.lastNames}" /> 
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{item.last_name}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{item.last_name}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
        </p:column>

1 个答案:

答案 0 :(得分:1)

您应该使用这组代码而不是代码。

ManagedBean

public class ClientsListBean implements Serializable{
private Set<String> lastNames = new HashSet<String>();

public ClientsListBean(){
    lastNames.add("john");
    lastNames.add("marry");
    lastNames.add("hudson");
}

/**
 * @return the lastNames
 */
public Set<String> getLastNames() {
    return lastNames;
}

/**
 * @param lastNames the lastNames to set
 */
public void setLastNames(Set<String> lastNames) {
    this.lastNames = lastNames;
}

}

数据表

<h:form>
        <p:dataTable id="table" value="#{clientsListBean.lastNames}" var="item" style="width:95%" styleClass="dataTable"
                     sortMode="multiple" paginator="true" rows="20"  editable="true" sortOrder="descending" 
                     draggableColumns="true" emptyMessage="No clients found with given search criteria"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >


            <p:column headerText="Last Name" filterBy="#{item}" sortBy="#{item}" style="width:auto; text-align:center" > 
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{item}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{item}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
        </p:dataTable>
    </h:form>