Filtering by enum values?

UI Components for JSF
Post Reply
oschell
Posts: 11
Joined: 03 Apr 2015, 09:29

07 Jun 2016, 16:51

Hi everyone,

I'm stuck with a simple task for a whole day now. I want to filter each column of my <p:dataTable>. As long as Properties are text based everything works well. But boolean and enum based types are behaving strangely. There is nothing or everything filtered. But sorting works fine. So I attached a filterFunction to see what's going on:

Code: Select all

<p:column headerText="Active" 
	sortBy="#{figure.active}"
	filterBy="#{figure.active}"
	filterFunction="#{basicFigureActions.filterBooleans}">
	<f:facet name="filter">
		<p:selectOneMenu id="soActiveFilter"
			onchange="PF('wgBasicFigures').filter()">
			<f:converter converterId="javax.faces.Boolean" />
			<f:selectItem itemValue="" itemLabel="All" noSelectionOption="yes" />
			<f:selectItem itemValue="true" itemLabel="Active" />
			<f:selectItem itemValue="false" itemLabel="Inactive" />
		</p:selectOneMenu>
	</f:facet>
	<c:trueOrFalseIcon value="#{figure.active}" />
</p:column>

<p:column headerText="Aggregation" 
	sortBy="#{figure.aggregation}"
	filterBy="#{figure.aggregation}" 
	filterFunction="#{basicFigureActions.filterAggregations}"
	styleClass="TexAlCenter">
	<f:facet name="filter">
		<p:selectOneMenu id="soAggregationFilter"
			onchange="PF('wgBasicFigures').filter()">
			<f:converter converterId="aggregationConverter" />
			<f:selectItem itemValue="#{null}" itemLabel="All" noSelectionOption="yes" />
			<f:selectItem itemValue="SUM" itemLabel="Sum" />
			<f:selectItem itemValue="AVERAGE" itemLabel="Average" />
			<f:selectItem itemValue="KEY_DATE" itemLabel="Key date" />
		</p:selectOneMenu>
	</f:facet>
	<c:figureAggregation value="#{figure.aggregation}" />
</p:column>

@Named
@ViewScoped
public class BasicFigureActions extends Action {

	public boolean filterAggregations( Object value, Object filter, Locale locale ) {
		// set breakpoint here
	}

	public boolean filterBooleans( Object value, Object filter, Locale locale ) {
		// set breakpoint here
	}
...
}
As you can see, Aggregation is an enum and active is a simple boolean. Interestingly the filter function for booleans gets called, the filter parameter is correct, but the value parameter is always false(though there are true-values in my column). And the enum filter function never gets called. After playing around with certain alternatives I got the enum filter function working, but as the filter param is correct, the value parameter remains null. As far as I could see while debugging there seems to be a problem with the org.primefaces.component.datatable.feature.FilterFeature class, whose filter method is not capable of resolving the enum using a ValueExpression that always delivers null for filterBy="#{figure.aggregation}". Did I miss something? Is there a workaround? Even the "old school" way of working with SelectItems does not help...

Thanks in advance,
Oliver

oschell
Posts: 11
Joined: 03 Apr 2015, 09:29

07 Jun 2016, 17:17

Me again,

don't know if this helps: the appropriate converters ARE properly used. Removing a working filter text from a view text field DOES restore filtered rows, but DOES NOT restore my boolean and enum based values. I can see that PF already loses this information while writing a selection into the "filteredValue" expression.

Greets,
Oliver

oschell
Posts: 11
Joined: 03 Apr 2015, 09:29

17 Jun 2016, 09:54

Hi everyone,

is there really nobody who has filtered a table using an enumeration property? :-)

Greets

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

17 Jun 2016, 11:23

You do know that the sorting and filtering occurs on the client unless you specify that the datatable is lazy and your data model extends LazyDataModel don't you?

Read the User Guide, study the show case.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

oschell
Posts: 11
Joined: 03 Apr 2015, 09:29

17 Jun 2016, 12:05

I studied the showcase very intensely, otherwise I would not ask in a forum. I am not sure whether I understand your hint. I am not using a LazyDataModel, but I can clearly trace that my filter text field fires an xhr request on every keyup event. This is answered by an xhr response doing a full table update, after walking through the designated filter function ( filterFunction="#{basicFigureActions.filterAggregations}" ). So - to my understanding - filtering happens on the server. Did I get somehting wrong?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests