Karthik
Karthik

Reputation: 21

Primefaces dataTable filter selectOneMenu not working

I am using PrimeFaces 5.1, In my project dataTable to filter used.In text filter is work fine but dropdown filter is not working properly (i.e) In dropdown I show department,First time I choose any value from dropdown is work fine anothertime I choose dropdown It not return any value show in dataTable.I choose select one first value from dropdown also throw null pointer exception.

<p:dataTable id="datalist" widgetVar="datalist" var="user" value=#{beanList.userList}>
<p:column headerText="Department" filterBy="#{user.deptname}"
            filterMatchMode="exact" >
      <f:facet name="filter">
          <p:selectOneMenu onchange="PF('datalist').filter()">
                <f:selectItem itemLabel="ALL" itemValue="#{null}"
                              noSelectionOption="true" />
                <f:selectItems value="#{datalist.deptList}" />
          </p:selectOneMenu>
      </f:facet>
      <h:outputText value="#{user.depatname}" />
</p:column>
</p:dataTable>

My doubt is default value ALL click and second time select any value return null or no data show in dataTable.

Upvotes: 1

Views: 2717

Answers (1)

Mistral
Mistral

Reputation: 126

Since I don't know the scope of your Managed Bean: Try a scope longer than request (see PrimeFaces 5.1 User Documentation), and provide a value "filteredValue" for your table, like this:

<p:dataTable id="datalist" widgetVar="datalist" var="user"
value="#{beanList.userList}" filteredValue="#{beanList.filteredUserList}">

With that, you make sure to keep your filtered table/list in a field in your managed bean and the contents won't get lost. Also, make sure your Managed Bean class is serializable (See this stackoverflow post)

Upvotes: 0

Related Questions