• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Smitha Dsouza
Greenhorn
Posts: 4
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Smitha,
thank you its worked for me
 
Tim Holloway
Saloon Keeper
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic