[
http://issues.apache.org/jira/browse/TOMAHAWK-523?page=comments#action_12423825
]
Eivind Rønnevik commented on TOMAHAWK-523:
------------------------------------------
I've encountered the same problem, and I also have the need of setting styles
dynamically. I'm currently using the 1.1.3 of both myfaces and tomahawk.
Basically, i need to set different background-colors for each row depending on
conditions. If condition is false, set color to either white or blue
(alternate), if condition is true, set color to yellow.
What I did as a workaround was to use the rowClasses attribute, and instead of
using an EL-expression I created a method in my bean that retrieves the value
of the dataTable (the objects it contains), runs through them and test for the
condition. Based upon the result I build a String of comma-separated values. So
this string (which then is bound to rowClasses attribute) contains a reference
to a style class for each row.
--------------.jsp---------------
<t:dataTable id="documentsTableView"
value="#{documentModelFactory.documents}"
var="document"
rowClasses="#{documentModelFactory.rowStyle}" >
------------- bean ---------------------
public String getRowStyle()
{
List<Document> contents= new ArrayList<Document>();
contents =(ArrayList<Document>)htmlDataTable.getValue();
String rowStyles = "";
int count = 2;
for (Document document : contents)
{
if (condition = true)
{
rowStyles += "yellow";
}
else
{
if (count % 2 == 0) //To alternate between to
colors
{
rowStyles += "white";
}
else if (count % 2 == 1)
{
rowStyles += "blue";
}
}
rowStyles+=",";
count++;
}
if(rowStyles != "" )
rowStyles =
rowStyles.substring(0,(rowStyles.length()-1)); //remove last comma
return rowStyles;
}
This worked for me..
What I wanted to do was something like this:
rowClasses="#{ test1 < test2 ? 'yellow':'white,blue'}"
The EL expression is rendered correctly (true when it's supposed to be true),
and even if yellow is set as rowClass for some rows, the html source have only
<tr class="blue" and "white" tags... And I can't understand why it always uses
the "false" result of the EL..
I don't know if you can make use of my suggestion but it's what I had to do to
get around the problem. :)
Regards,
Eivind
> rowStyleClass does not resolve to an EL of var
> ----------------------------------------------
>
> Key: TOMAHAWK-523
> URL: http://issues.apache.org/jira/browse/TOMAHAWK-523
> Project: MyFaces Tomahawk
> Issue Type: Bug
> Components: Extended Datatable
> Affects Versions: 1.1.4-SNAPSHOT
> Environment: Tomcat, Facelets
> Reporter: James McCarthy
>
> The rowStyleClass does not resolve when the rowStyleClass references an EL
> item identified by var. var="item" rowStyleClass="#{item.status}".
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira