简体   繁体   English

Primefaces dataTable过滤器selectOneMenu不起作用

[英]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 (ie) 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. 我正在使用PrimeFaces 5.1,在我的项目数据表中使用过滤器。在文本过滤器中工作正常,但下拉过滤器无法正常工作(即)在下拉菜单中显示部门,第一次选择下拉菜单中的任何值都可以正常工作dropdown它不返回dataTable中显示的任何值。我选择从dropdown中选择一个第一个值,还会抛出空指针异常。

<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. 我的疑问是默认值ALL单击,第二次选择任何值返回null或dataTable中没有数据显示。

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: 由于我不知道您的Managed Bean的范围,请执行以下操作:尝试将范围长于请求的范围(请参阅PrimeFaces 5.1用户文档),并为表提供一个值“ filteredValue”,如下所示:

<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. 有了它,您确保将过滤的表/列表保留在托管bean的字段中,并且内容不会丢失。 Also, make sure your Managed Bean class is serializable ( See this stackoverflow post ) 另外,请确保您的Managed Bean类是可序列化的( 请参阅此stackoverflow文章

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

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