DataTable improvement for dynamic column (patch included)

UI Components for JSF
Post Reply
alfonx
Posts: 93
Joined: 15 Mar 2010, 18:50
Contact:

26 Aug 2013, 16:54

Hi

I use DataTable with dynamic column like this:

Code: Select all

<p:columns value="#{abfrageBean.getErgebnisColumnModel()}" var="column">
	<h:outputText  value="#{row.getWertFormatted(column.property)}" />
...
Original methode resolveDynamicField(..) in DataTable.java is:

Code: Select all

    public String resolveDynamicField(ValueExpression expression) {
        if(expression != null) {
            String expressionString = expression.getExpressionString();
            expressionString = expressionString.substring(expressionString.indexOf("[") + 1, expressionString.indexOf("]"));            
            expressionString = "#{" + expressionString + "}";
which fails in my case because it expects the dynamic column value to be retrived like:

Code: Select all

<h:outputText value="#{row[column.property]}" />
But in my case the columns are really dynamic, so there are no getters. To make it work I patch DataTable in every release with

Code: Select all

public String resolveDynamicField(ValueExpression expression) {
if (expression != null) {
	String expressionString = expression.getExpressionString();

       // PATCH INSERT START
   if (expressionString.indexOf("[") < 0)
     expressionString = expressionString.substring(expressionString.indexOf("(") + 1,expressionString.indexOf(")"));
   else
     expressionString = expressionString.substring(expressionString.indexOf("[") + 1,expressionString.indexOf("]"));
       // PATCH INSERT END

       expressionString = "#{" + expressionString + "}";
I am using this in production since weeks.. I guess both aproaches aren't perfect, but mine is supporting one more case.

May I open a ticket for these 4 lines to be commited into trunk?
Greetings,
Steve

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

26 Aug 2013, 17:45

alfonx wrote: To make it work I patch DataTable in every release with
Every 3.5.x? 4.0-SNAPSHOT?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Aug 2013, 17:49

These do not apply 4.x I think as we removed resolve field stuff.

alfonx
Posts: 93
Joined: 15 Mar 2010, 18:50
Contact:

26 Aug 2013, 20:40

kukeltje wrote:
alfonx wrote: To make it work I patch DataTable in every release with
Every 3.5.x? 4.0-SNAPSHOT?
Sorry, I should have been more precise. I had to patch it since 3.4.something and in each of the 3.5.x releases.

So do i understand it correctly, that in 4.0 this is resolved?
Greetings,
Steve

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Aug 2013, 22:57

resolve-* method are not used in 4.0, I've just realized that I forgot to remove them. If you have a chance please try with 4.x build and let us know.

alfonx
Posts: 93
Joined: 15 Mar 2010, 18:50
Contact:

22 Apr 2014, 12:21

I migrated to 4.12 now, and it's NOT working out of the box. The resolve-Methods are still called:

Code: Select all

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1911)
        at org.primefaces.component.datatable.DataTable.resolveDynamicField(DataTable.java:865)
        at org.primefaces.component.datatable.DataTable.resolveSortField(DataTable.java:831)
        at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:770)
        at org.primefaces.component.datatable.feature.SortFeature.encode(SortFeature.java:108)
        at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:76)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1826)
Probably out of this XHTML:
<p:columns value="#{abfrageBean.getColumnModel()}"
id="columnsDynamic" var="column"
sortBy="#{row.getValueForColumn(column.property)}">
...
Greetings,
Steve

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

22 Apr 2014, 12:26

We have introduced field attribute in column and columns that is used to avoid getting field information from the EL in 5.0.

alfonx
Posts: 93
Joined: 15 Mar 2010, 18:50
Contact:

22 Apr 2014, 12:29

Thanks for your quick answer. So in PF5 you added a field attribute.
For 4.12 my old patch still works fine after 5min testing:

Code: Select all

public String resolveDynamicField(ValueExpression expression) {
if (expression != null) {
   String expressionString = expression.getExpressionString();

       // PATCH INSERT START
   if (expressionString.indexOf("[") < 0)
     expressionString = expressionString.substring(expressionString.indexOf("(") + 1,expressionString.indexOf(")"));
   else
     expressionString = expressionString.substring(expressionString.indexOf("[") + 1,expressionString.indexOf("]"));
       // PATCH INSERT END

       expressionString = "#{" + expressionString + "}";
Greetings,
Steve

alfonx
Posts: 93
Joined: 15 Mar 2010, 18:50
Contact:

22 Jul 2014, 00:04

Some update on this with PF 5.0.4:

Code like:

Code: Select all

<p:columns value="#{abfrageBean.getColumnModel()}"
id="columnsDynamic" var="column"
sortBy="#{row.getValueForColumn(column.property)}">
works in primefaces 5 without my patch needed anymore! Great!

Post by optimus.prime » Mon Aug 26, 2013: resolve-* method are not used in 4.0, I've just realized that I forgot to remove them.
public String resolveDynamicField(ValueExpression expression) is still in DataTable.java PF 5.0.4, but it is not used anymore to resolve the above XHTML.

Thanks
Steve
Greetings,
Steve

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests