Question

I've recently changed from TomEE 1.5.2 to 1.6.0 which has upgraded MyFaces from 2.1.10 to 2.1.13. I'm now seeing unusual results in dataTable column styles.

This works fine:

<h:dataTable value="#{testView.dataList}" var="r" columnClasses="col1,col2,col3,col4">
    <h:column><f:facet name="header">Col 1</f:facet>#{r.col1}</h:column>
    <h:column><f:facet name="header">Col 2</f:facet>#{r.col2}</h:column>
    <h:column><f:facet name="header">Col 3</f:facet>#{r.col3}</h:column>
    <h:column><f:facet name="header">Col 4</f:facet>#{r.col4}</h:column>
</h:dataTable>

If, however, the columns have a rendered attribute which evaulates to false then the column class gets messed up.

<h:dataTable value="#{testView.dataList}" var="r" columnClasses="col1,col2,col3,col4">
    <h:column><f:facet name="header">Col 1</f:facet>#{r.col1}</h:column>
    <h:column><f:facet name="header">Col 2</f:facet>#{r.col2}</h:column>
    <h:column rendered="false"><f:facet name="header">Col 3</f:facet>#{r.col3}</h:column>
    <h:column><f:facet name="header">Col 4</f:facet>#{r.col4}</h:column>
</h:dataTable>

gives

<tr>
    <td class="col1">col1</td>
    <td class="col2">col2</td>
    <td class="col3">col4</td>
</tr>

Column 3 has not been rendered as expected, but column 4 has been given the col3 style instead of the col4 one. As I said it work as I was expecting prior to 2.1.13, so do you think this is a MyFaces bug?

Était-ce utile?

La solution

It is not a bug, instead by spec, columnClasses is applied sequentially to the active columns. It was a fix in MYFACES-3749, but I checked it with the latest version of Mojarra and it works the same.

My suggestion is use tomahawk extended datatable, that works just like h:datatable but with some extended features. In your case you can set the styleClass of the column in this way.

<t:datatable var="row" ...>
   <t:column styleClass="#{row.styleClass}">
   ...
   </t:column>
</t:datatable>

This issue has been already reported in the spec. See JAVASERVERFACES_SPEC_PUBLIC-217.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top