given the following primefaces Data
<p:dataTable value="#{cc.attributes.playerCollection}" var="player"
widgetVar="playerWidgetTable" emptyMessage="#{uimsg.ui_not_recordsfound}">
<!-- filter event handler -->
<p:ajax event="filter" listener="#{cc.attributes.viewBean.listenFilter}" update="@this"/>
<!-- Player first name -->
<p:column id="firstnameColumn" headerText="#{uimsg.firstname}"
filterBy="#{player.firstName}" filterMatchMode="contains">
<h:outputText value="#{player.firstName}" />
</p:column>
</p:dataTable>
how does someone get (on the server side) the filter “Text” value, given by the user in the filter textcolumn ?
i tried to listen to the filter event with “listenFilter”:
@ManagedBean
@ViewScoped
public class PlayerListBean implements Serializable {
......
public void listenFilter(FilterEvent event) {
// update datasource
Map<String, String> tempString = event.getFilters();
System.out.println("size filter: "+ tempString.size());
for (String key : tempString.keySet()) {
System.out.println("key: " + key + " \t values: "
+ tempString.get(key));
}
}
}
but I can’t start something with it.
are they any other options ? like working with the DataTable as a bound Component, or else ?
thanks
What I normally do is to use an actual DataModel to feed to the dataTable component instead of using a plain collection, like you seem to be doing (you didn’t post the rest of your bean). I extend the LazyDataModel class and override the load() method, whose signature is:
In this case, the filter field (map) contains whatever the user entered on each filter. Also, you don’t really need any ajax listeners for the filter. I use this in my projects and it works just fine. Let me know if you need further assistance.