I've got a problem with the column tag in a primeface datatable. I've got a model with a lot of similar fields so in order to reduce code, I'm trying to have a custom made tag to fill each column. So rather having to write something like
<p:column headerText="MyHeader" filterBy="#{d.two}" styleClass="ps-footprint-type ps-vertical-title" >
<f:facet name="filter">
<p:triStateCheckbox onchange="PF('w_footprintsTable').filter()" converter="triStateBooleanConverter" />
</f:facet>
<h:panelGroup rendered="#{d.two}"> <i class="pi pi-check">v</i> </h:panelGroup>
</p:column>
I'm trying to have something like
<sjsf:booleanColumn value="#{d.two}" header="MyHeader" tableWidget="w_footprintsTable"/>
By following advice from @Jasper in the following thread, I've managed to do most of it using a facelet tag. The only problem is the filtering. It works fine for explicit column but it only works on the last column when using my facelet tag.
I've created a little git project here to show all the code and run it if needed. It will display the following page. The first 3 boolean columns are explicit <p:column> tags (the filtering works for all three), the next 3 boolean columns use my facelet tag and as you can see, column "four" doesn't filter correctly but column "six" does.
Anybody faced this kinda of issue and was able to solve it?
PS: this is the code of my custom tag
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite">
<p:column headerText="#{header}" filterBy="#{value}" styleClass="sj-vertical-title" >
<f:facet name="filter">
<p:triStateCheckbox onchange="PF('#{tableWidget}').filter()" converter="triStateBooleanConverter" />
</f:facet>
<h:panelGroup rendered="#{value}">
<i class="pi pi-check">V</i>
</h:panelGroup>
</p:column>
</ui:composition>
Although it is documented as kind of optional, in our case, we had to add the field
attribute. I think it was because custom tag attributes could not be resolved in the filter request. So use:
<p:column filterable="true" field="#{property}" ... />
For other uses we added custom tag attributes to a component using:
<f:attribute name="myAttr" value="#{myAttr}" />
which you are able to read later via:
#{component.attributes.myAttr}
or:
#{component.parent.attributes.myAttr}
depending on the component.