2

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.

enter image description here

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>
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
willix
  • 686
  • 1
  • 6
  • 13

1 Answers1

2

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.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Thanks but that was unfortunately not it. I modified my tag like you suggested but it still only works for the last column. I even swapped the columns just to make sure and it still only works for the last one. – willix Mar 24 '21 at 08:45
  • I thought it was minimal but you right, there are a few too many extras on the datatable. I've removed most of the overhead but it still fails... – willix Mar 24 '21 at 10:03
  • I've tried using a LazyDataModel and when the load method is being called after a clicked on a filter box, the filterBy map only contains 4 entries (the 3 that use an explicit p:column and the last of the taglib one). So I'm missing 2. Looks like all the taglib one have the same key so the last one overwrites the first two. – willix Mar 24 '21 at 10:18
  • Yep the field attribute did the trick (never really noticed it in any examples)! Thanks a lot! – willix Mar 24 '21 at 11:59