datatable and row var

UI Components for JSF
Post Reply
derek
Posts: 57
Joined: 24 Aug 2010, 00:56
Location: Canada

15 Sep 2010, 20:00

I'm trying to make my datatables row's alternate colors, I have tried the following, but for some reason the 1st 2 rows are always the same color.. maybe this is a bug?

Code: Select all

<p:dataTable dynamic="true" value="#{ListBean.list.contacts}" var="contact" rows="30" paginator="true" rowIndexVar="row" rowStyleClass="#{row % 2 == 0 ? 'tteven' : 'ttodd'}">
...
</p:dataTable>
Last edited by derek on 12 Oct 2010, 23:38, edited 1 time in total.
PrimeFaces-3.0, Mojarra 2.0.4, GlassFish 3.1

derek
Posts: 57
Joined: 24 Aug 2010, 00:56
Location: Canada

15 Sep 2010, 20:02

after a little more experimentation, I found this solution

Code: Select all

<p:dataTable dynamic="true" value="#{ListBean.list.contacts}" var="contact" rows="30" paginator="true" rowIndexVar="row" rowStyleClass="#{(row == null || row % 2 != 0) ? 'tteven' : 'ttodd'}">
...
</p:dataTable>
it seems that the 1st row is null?
PrimeFaces-3.0, Mojarra 2.0.4, GlassFish 3.1

sky_java_seb
Posts: 10
Joined: 20 Mar 2010, 03:12

22 Sep 2010, 10:40

Hi,

Indeed I got same problem. It's a bit weird cause if you output something like #{ row mod 2 } in a column it resolves correctly {0,1} for first lines.
I wonder why it fails in a test as precedence is respected but there shall be a hiden trick or bad convertion used in rowIndexVar value generation (primefaces dependent) or in EL resolution (surely JSF based ?).

Maybe a primefaces master could send a quick look in dataTable rowIndexVar code ? :roll:

It's good there is a solution but I don't like using such "dirty" code on such supposed simple things,... unless there is a good reason :D

gschmidl
Posts: 3
Joined: 24 Sep 2010, 11:16

24 Sep 2010, 11:18

I can confirm this happens in JBoss 6 as well.

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

24 Sep 2010, 13:13

what about the rowIndexVar-value if you add:

Code: Select all

<p:column>
    <f:facet name="header">rowIndexVar</f:facet>
    <h:outputText value="#{row}"/>
</p:column>
with attr. rowIndexVar="row"
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

derek
Posts: 57
Joined: 24 Aug 2010, 00:56
Location: Canada

12 Oct 2010, 23:35

adding in

Code: Select all

<p:column>
    <f:facet name="header">rowIndexVar</f:facet>
    <h:outputText value="#{row}"/>
</p:column>
displays as expected (starts a 0 and counts up)

even doing

Code: Select all

<p:column>
    <f:facet name="header">rowIndexVar</f:facet>
    <h:outputText value="#{row % 2 == 0}"/>
</p:column>
displays true/false/true/false/etc..

edit: thats exactly what sky_java_seb said above :mrgreen:

Derek
PrimeFaces-3.0, Mojarra 2.0.4, GlassFish 3.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests