繁体   English   中英

在datatable列的过滤器中自动完成,素数

[英]autocomplete in datatable column's filter, primefaces

我正在尝试向datable的列中添加某种方式来过滤自动完成功能。 我创建了使用客户的姓氏设置的Set,还根据示例中的要求在Bean中创建了具有getter + setter的String文本字段,但是不知道如何添加过滤器。 您能帮我吗?

在豆

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>

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

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>

暂无
暂无

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

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