用动态列过滤掉一个懒惰的dataTable [英] Filter a lazy dataTable with dynamic columns
问题描述
我有一个包含动态列的dataTable:
< p:dataTable id =bookingsvar =booking value =#{tableBean.dataModel}
widgetVar =bookingTablefilteredValue =#{tableBean.filteredFields}
paginator =truerows =15
lazy = truerowsPerPageTemplate =15,30,50type =nonedraggableColumns =true>
[...]
< p:columns value =#{tableBean.columns}var =columncolumnIndexVar =colIndex
sortBy =#{booking.properties [column.property]}
filterBy =#{booking.properties [column.property]}
filterMatchMode =in
styleClass = telegrotesk>
< f:facet name =header>
< h:outputText value =#{column.header}/>
< / f:facet>
< f:facet name =filter>
< p:selectCheckboxMenu label =#{column.header}onchange =PF('bookingTable')。filter()>
< f:selectItems value =#{column.possicable}/>
< / p:selectCheckboxMenu>
< / f:facet>
< h:outputText value =#{booking.properties [column.property]}/>
< / p:columns>
列类似于原型示例( http://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml )这个类:
static public class ColumnModel implements Serializable {
private String header;
private String property;
私人列表< SelectItem>可能性
public ColumnModel(Field property){
this.header = property.getName();
this.property = property.getSqlName();
}
public String getHeader(){
return header;
}
public String getProperty(){
return property;
}
public List getPossabilities(){
return possible;
}
public void setPossabilities(List< SelectItem>可能性){
this.possibilities =可能性;
}
}
在我的示例中,仅测试一个动态列,显示创建预订的用户。它的工作原理,在checkboxdropdowndown显示所有用户。当我选择一个或多个用户时,功能加载
public List< Booking> load(int first,int pageSize,String sortField,SortOrder sortOrder,Map< String,Object> filters){
pre>
[...]
}
被执行,但过滤器始终为空!
ColumnModel
是SelectItems
的集合。标签始终是用户名,用户对象的值。对于用户类,我定义了一个实现javax.faces.convert.Converter
的转换器类与@FacesConverter(forClass = User.class)
过滤器地图始终为空,我做错了什么?
编辑
当我这样做
< p:columns value =#{tableBean.columns}var =columncolumnIndexVar =colIndex
sortBy =#{booking.properties [column.property]}
filterBy = #{booking.properties [column.property]}
filterMatchMode =in
filterOptions =#{column.possibilities}
styleClass =telegrotesk>
,没有任何方面可以正常工作,但我只能选择一个用户。
我使用的是原点5.0,jsf 2.2.1和glassfish v4
解决方案没有任何错误,这是一个原始的错误。
请加星标,让我们尝试一下。
新的PF5增强过滤功能不适用于动态列:
https: //code.google.com/p/primefaces/issues/detail?id=6912
解决方法:
步骤1:在原始源中( https://code.google.com/p/primefaces/source/checkout )打开FilterFeature.java。
在
populateFilterMetaData(FacesContext context,DataTable表)
方法,绕行300,替换:filterId = dynamicColumn.getContainerClientId(context)+ separator +filter;
dynamicColumn.cleanStatelessModel();
与此:
filterId = dynamicColumn.getContainerClientId(context)+ separator +filter;
filterFacet = null;
dynamicColumn.cleanStatelessModel();
所以基本上你只需添加
filterFacet = null;
建立PF的提示: https://code.google.com/p/primefaces/wiki/BuildingFromSource
步骤2:在您的项目中,确保过滤器构面中的输入组件的ID为过滤器
示例:
< f:facet name =filter>
< p:selectOneButton id =filteronchange =PF('recordTable')。filter()>
< f:converter converterId =javax.faces.Boolean/>
< f:selectItem itemLabel =全部itemValue =/>
< f:selectItem itemLabel =TrueitemValue =true/>
< f:selectItem itemLabel =FalseitemValue =false/>
< / p:selectOneButton>
< / f:facet>
I have a dataTable with dynamic Columns:
<p:dataTable id="bookings" var="booking" value="#{tableBean.dataModel}" widgetVar="bookingTable" filteredValue="#{tableBean.filteredFields}" paginator="true" rows="15" lazy="true" rowsPerPageTemplate="15,30,50" type="none" draggableColumns="true"> [...] <p:columns value="#{tableBean.columns}" var="column" columnIndexVar="colIndex" sortBy="#{booking.properties[column.property]}" filterBy="#{booking.properties[column.property]}" filterMatchMode="in" styleClass="telegrotesk"> <f:facet name="header"> <h:outputText value="#{column.header}"/> </f:facet> <f:facet name="filter"> <p:selectCheckboxMenu label="#{column.header}" onchange="PF('bookingTable').filter()"> <f:selectItems value="#{column.possibilities}" /> </p:selectCheckboxMenu> </f:facet> <h:outputText value="#{booking.properties[column.property]}"/> </p:columns>
column is similar like in the primefaces example (http://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml) this class:
static public class ColumnModel implements Serializable { private String header; private String property; private List<SelectItem> possibilities; public ColumnModel(Field property) { this.header = property.getName(); this.property = property.getSqlName(); } public String getHeader() { return header; } public String getProperty() { return property; } public List getPossibilities() { return possibilities; } public void setPossibilities(List<SelectItem> possibilities) { this.possibilities = possibilities; } }
In my example there is for testing only one dynamic column, that shows the User that created a booking. It works, that in the checkboxdropdown are shown all users. When I select one or more users, the function load
public List<Booking> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters) { [...] }
is executed, but filters is always empty!
The list possibilities in the
ColumnModel
is a Collection ofSelectItems
. The label is always the username, the value the User object. For the user class I defined a Converter class implementingjavax.faces.convert.Converter
with the@FacesConverter(forClass = User.class)
What am I doing wrong that the filter map is always empty?
EDIT
When I do it like this
<p:columns value="#{tableBean.columns}" var="column" columnIndexVar="colIndex" sortBy="#{booking.properties[column.property]}" filterBy="#{booking.properties[column.property]}" filterMatchMode="in" filterOptions="#{column.possibilities}" styleClass="telegrotesk">
and with no facet it works correctly but I can only select one User.
I'm using primefaces 5.0, jsf 2.2.1 and glassfish v4
解决方案You did nothing wrong, this is a Primefaces bug.
Please star it, let's try and get it fixed.
New PF5 enhanced filtering does not work with Dynamic Columns: https://code.google.com/p/primefaces/issues/detail?id=6912
Workaround:
Step 1: In the Primefaces source (https://code.google.com/p/primefaces/source/checkout) open FilterFeature.java.
In the
populateFilterMetaData(FacesContext context, DataTable table)
method, around line 300, replace:filterId = dynamicColumn.getContainerClientId(context) + separator + "filter"; dynamicColumn.cleanStatelessModel();
with this:
filterId = dynamicColumn.getContainerClientId(context) + separator + "filter"; filterFacet = null; dynamicColumn.cleanStatelessModel();
So basically you just add
filterFacet = null;
Tips for building PF: https://code.google.com/p/primefaces/wiki/BuildingFromSource
Step 2: In your project, ensure that your input component in the filter facet has an id of filter
Example:
<f:facet name="filter"> <p:selectOneButton id="filter" onchange="PF('recordTable').filter()" > <f:converter converterId="javax.faces.Boolean" /> <f:selectItem itemLabel="All" itemValue="" /> <f:selectItem itemLabel="True" itemValue="true" /> <f:selectItem itemLabel="False" itemValue="false" /> </p:selectOneButton> </f:facet>
这篇关于用动态列过滤掉一个懒惰的dataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!