DataTable - Dynamic Columns - Topic unanswered

UI Components for JSF
Post Reply
Rafaelfr1
Posts: 32
Joined: 09 Mar 2015, 16:03

22 Jul 2017, 15:00

Hi

I'm opening this post because I searched the forum and found a case similar to mine, but there was no response. I already looked a lot in the forums but could not find a solution.
See another unanswered topic here viewtopic.php?f=3&t=43490

If I read columns from the table it works. But we have follow construct and than it dosn't work.

I have a table called TITLE with CONSTRAINT to a table PERSON. When we read the TITLE from the database (JPA) we get the object PERSON in the bean
In the ManagedBean I define the columns for the DataTable:
private String[] columnTitle= {"id", "value", "person.name"};

In the page I define the columns:

Code: Select all

 <p:columns value="#{reportView.columns}" var="column" columnIndexVar="colIndex" sortBy="#{title[column.property]}" 
              filterBy="#{title[column.property]}" filterMatchMode="contains" style="width: #{column.size} !important" >
    <f:facet name="header">
         <h:outputText value="#{column.header}" />
    </f:facet>
    <h:outputText value="#{title[column.property]}" />
    <f:facet name="footer">
         <h:outputText value="#{column.header}" />
    </f:facet>
</p:columns>
And now I get follow error:
The class 'com.system.domain.Title' does not have the property 'person.name'.
But in the PERSON there is a property "name".

Can somebody tell me, how we can use properties from an object in an object?

pilpin
Posts: 16
Joined: 05 Jan 2017, 20:55

24 Jul 2017, 08:33

I think the problem comes from the fact that you're trying to display 'title[...]' which does not exist, but 'reportView.title[...]' should, or is title the var from the datatable ?

Could you share the whole <p:datatable ... > code ? The code from the bean would help as well.
PrimeFaces 6.2
Payara 5.182

Rafaelfr1
Posts: 32
Joined: 09 Mar 2015, 16:03

24 Jul 2017, 13:39

Good morning, I was able to solve it as follows. Each [...] is considered as attribute access, so to access the next attribute would be as title [column.property] [column.propertyTwo] and so on.

The question I still have is because every time I have to access the second property I would have to put one more bracket [...]. So the code would look a little strange if for example I want to access the fifth property: For example it would look like this:

Code: Select all

#{column.propertyTwo eq null ? title[column.property] : 
                                                       column.propertyThree eq null ? title[column.property][column.propertyTwo] : 
                                                       column.propertyFour eq null ? title[column.property][column.propertyTwo][column.propertyThree] : 
                                                       title[column.property][column.propertyTwo][column.propertyThree][column.propertyFour]}
Imagine that for each new attribute access I have to create a new "IF" so I can access it, is it correct to express it this way?

Rafaelfr1
Posts: 32
Joined: 09 Mar 2015, 16:03

26 Jul 2017, 14:14

I found a problem when using this implementation, in the filterby when using this way it presents a null pointer.


Any answers?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 36 guests