0
  1. I have 2 beans, beanA has fileds namefilter,agefilter,nationfilter, beanB also has 3 fields but with different names
  2. I have an xhtml template, inside which is a dataTable, each column should have a filter, so I'll set filterValue="#{beanname.properryname}"

I want to reuse this template so I'm passing bean and list of attribute like this

<ui:include src="TemplateTable.xhtml">
    <ui:param name="bean" value="#{beanA}"/>
    <ui:param name="filters" value="namefilter, agefilter, nationfilter"/>
</ui:include>

inside the template I'll do

<c:set var="filterList" value="filters, ',')}"/

<p:columns value="xxxx" var = "column" filterValue="#{bean.filterList[colIndex]}">
    <!--tilte and text here-->
</p:columns>

But above code doesn't work, it resolved filterList as a property name but what I actually want in this case is

filterValue="{beanA.nameFilter}"
filterValue="{beanA.ageFilter}"
filterValue="{beanA.nationFilter}"

anyone knows how to do it?

Let me elaborate my question more.

What I want is to create a template with a filterable datatable, filter text can be saved as bean property so that when I navigate into/away from the page, filter text doesn't lose.

Theoretically, below code should work

<p:columns value="#{table.columnList}"
    var="column" 

    sortBy="#{row[column.sortField]}" 
    filterBy="#{row[column.sortField]}" 
    filterValue="#{bean[column.sortField]}" filterMatchMode="contains">


    <f:facet name="header">
        <h:outputText value="#{column.header}" />                    
    </f:facet>
    <h:outputText value="#{row[column.field]}" escape="false"/>
</p:columns>

here column list is like

[header:"NAME", field:"name", sortField:"name"],
[header:"AGE",  field:"age",  sortField:"age"],

The page can be shown but as soon as I input a char into filter for 'name', I can see setName() is called on the bean with the correct text value, but there's a crash

[8/10/19 16:41:20:135 AEDT] 0000010a SystemErr     R javax.el.PropertyNotFoundException: /pagesworkingItems/test.xhtml at line 39 and column 71 filterValue="#{bean[column.sortField]}": Target Unreachable, 'BracketSuffix' returned null
[8/10/19 16:41:20:135 AEDT] 0000010a SystemErr     R    at org.apache.myfaces.view.facelets.el.TagValueExpression.setValue(TagValueExpression.java:121)
[8/10/19 16:41:20:135 AEDT] 0000010a SystemErr     R    at org.primefaces.component.datatable.DataTable.processUpdates(DataTable.java:921)

At the same time, if I instead hardcode, everything is fine. Like this:

<p:column sortBy="#{row.name}" filterBy="#{row.name}" filterValue="#{bean.name}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="name" />                    
        </f:facet>
        <h:outputText value="#{row.name}" escape="false"/>
</p:column>

<p:column sortBy="#{row.age}" filterBy="#{row.age}" filterValue="#{bean.age}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="age" />                    
        </f:facet>
        <h:outputText value="#{row.age}" escape="false"/>
</p:column>

So the problem must be in filterValue="#{bean[column.sortField]}" But I don't know how/why.

rhbc73
  • 739
  • 9
  • 24
  • What is filtetlist? Please expand your question to include a [mcve] and precise problem description + full error messqges if present. – Selaron Oct 04 '19 at 07:20
  • 1
    I suspect that he ultimately needs `#{bean[filterList[colIndex]]}`. – BalusC Oct 04 '19 at 09:53
  • You edited your question yet again. But the same answer holds true. If `sortField` is also a variable and not a hardcoded name (i.e. you actually want to use the result of `#{sortField}`), then use `#{bean[column[sortField]]}`. – BalusC Oct 08 '19 at 11:47

0 Answers0