wood burning stoves 2.0*
The moose likes JSF and the fly likes h:dataTable rowClasses attribute can be used to colorise each row based on bean property value. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:dataTable rowClasses attribute can be used to colorise each row based on bean property value." Watch "h:dataTable rowClasses attribute can be used to colorise each row based on bean property value." New topic
Author

h:dataTable rowClasses attribute can be used to colorise each row based on bean property value.

Smitha Dsouza
Greenhorn

Joined: Feb 10, 2012
Posts: 3

Hi This post regarding h:dataTable rowClasses attribute.

Hope this will be useful for you also as i have used in my code.


Out put should be a Table with row colored depending on the status of the each student.

so in my jsp i addded
<style>
.redcolor{
background-color:rgb(250,128,114);
}
.blueColor{
background-color:rgb(135,206,250);
}
.yellowColor{
background-color:rgb(255,255,224);
}
.whiteColor{
background-color:white;
}
</style>
within the head tag and the table as
<h:dataTable id="UnAssignedTable" width="100%" value="#{studentAGAssign.studentBasicVOList}" var="item" rowClasses="#{studentAGAssign.rowColor}">
</h:dataTable>

In my bean file i added rowColor as String variable with its getter and setter methods.
and initialize the rowColor variable with the css class name specified in the jsp page according to each student status which is in the below java code using string builder:
StringBuilder strBuild=new StringBuilder();


for(StudentBasicVO student:studentBasicVOList){
strBuild.append(getRowColor(student));
strBuild.append(',');
}
int length= strBuild.length();
if(length>0){
strBuild.deleteCharAt(length-1);
// strBuild.append(';');
rowColor=new String(strBuild);
}
public String getRowColor(StudentBasicVO stu){
String rowColor="whiteColor";
if(stu.isApplied()){
rowColor="yellowColor" ;
}else if(stu.isConfirmed()){
rowColor="blueColor";
}else if(stu.isCompleted()){
rowColor="redColor";
}


return rowColor;
}



Please post your comments if anything new and more good can be done in this. :thumbup
Google:
h:dataTable rowClasses attribute
Sushma Bevoor
Greenhorn

Joined: Apr 26, 2013
Posts: 2
Hi Smitha,
thank you its worked for me
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Helpful hint:

If you use the "Code" button on the JavaRanch message editor, it will insert code tags that can be used to wrap pre-formatted data such as Java code and XML (xhtml). That makes them easier to read and preserves the formatting.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: h:dataTable rowClasses attribute can be used to colorise each row based on bean property value.