【问题标题】:autocomplete in datatable column's filter, primefaces数据表列的过滤器中的自动完成,primefaces
【发布时间】:2014-11-12 03:18:02
【问题描述】:

我试图以某种方式添加到数据表的列过滤自动完成功能。我使用客户端的 LastNames 创建了 Set,还根据示例中的要求在我的 Bean 中使用 getter+setter 创建了 String 文本字段,但不知道如何将其添加到过滤器中。你能帮我解决一下吗!?

在 Bean 中

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

数据表

<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>

【问题讨论】:

    标签: jsf-2 primefaces datatable


    【解决方案1】:

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

    托管豆

    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>
    

    【讨论】:

    • 谢谢,但我想我必须更改 primefaces jar 文件中的代码,因为它没有这个选项!
    猜你喜欢
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    相关资源
    最近更新 更多