java.lang.NullPointerException at org.primefaces.component.datatable.feature.FilterFeature.filter

后端 未结 1 591
广开言路
广开言路 2020-12-12 01:19

I\'m trying create a filter to one dataTable. I want that filter works with all keywords contained in datatable.

I am following examples at: http://www.primefaces.or

相关标签:
1条回答
  • 2020-12-12 01:48

    You must put your p:datatable inside h:form like this.

        <h:form id="form-list-equipamentos">
            <p:dataTable id="equipamentos" 
                         var="equipamento" 
                         value="#{equipamentoBean.equipamentos}" 
                         widgetVar="equipamentoTable" 
                         filteredValue="#{equipamentoBean.equipamentosFiltrados}"
                         emptyMessage="Nenhum equipamento encontrado" 
                         resizableColumns="true">
    
                <f:facet name="header">
                    Lista de equipamentos
                    <!--            DESLIGAR COLUNAS -->
                    <p:commandButton id="toggler" 
                                     type="button" 
                                     value="Colunas"
                                     style="float:right" 
                                     icon="ui-icon-calculator" />
                    <p:columnToggler datasource="equipamentos" 
                                     trigger="toggler" />
    
                    <!--            BUSCA -->
                    <p:outputPanel>
                        <h:outputText value="Busca em todos os campos:"/> 
                        <p:inputText id="globalFilter"
                                     onkeyup="PF('equipamentoTable').filter()" 
                                     style="width:250px"
                                     placeholder="Palavra-chave para busca" />
                    </p:outputPanel>            
                </f:facet>
    
                <p:column filterBy="#{equipamento.nome}" 
                          sortBy="#{equipamento.nome}" 
                          headerText="Nome" filterMatchMode="contains">
                    <h:outputText value="#{equipamento.nome}"></h:outputText>
                </p:column>
    
            </p:dataTable>
        </h:form>
    

    Also watchout that your equipamentoBean is in proper scope (mine: javax.faces.view.ViewScoped).

    OT: I would recommend you to "id" the f:form tag as this gives you the possibility to update it after a "create" form (outside this form!) has added a record:

        <h:form>
        ....
            <p:commandButton
                type="submit"
                value="Add something"
                action="#{someBackingBean.addSomething()}"
                update=":master:form-list-equipamentos:equipamentos"
                />
        </h:form>
    

    The id="master" is in my "master" template where all other views derive from:

        <h:body>
            <pm:page id="master">
            ...
            </pm:page>
        </h:body>
    
    0 讨论(0)
提交回复
热议问题