Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

highlight a row in a datatable  RSS feed

 
Tammy Easterby
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need an EXAMPLE on how to do this. Basically I am going to set a flag on my backing bean to say "highlight me". And then how do I code the .jsp so that the <h:dataTable knows to override the rowClasses attribute to a highlight?

THANKS!
[ April 25, 2007: Message edited by: Tammy Easterby ]
 
Tammy Easterby
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm responding to my own topic, in case anyone else has the same question:
--------------------------------------------------------------------------

What you have to do is this:
1 - Create a converter. In that converter, you go:

HtmlDataTable table = (HtmlDataTable) component.getParent().getParent();
- where component is the UIComponent argument that was passed in.

Then, you go:

List col = table.getChildren();
for (int i = 0; i < col.size(); i++) {
if (col != null) {
List col1 = ((UIColumn) col.get(i)).getChildren();
for (int k = 0; k < col1.size(); k++) {
if (col1 != null) {
try {

- Here is where you put your logic. If some condition is met, then you put a highlight. If not, then the background is white, or gray or whatever the default color for your page is.

And this is how you set the color:

((HtmlOutputText) col1.get(k)).setStyle("background-color:yellow");

Of course, if the condition is false and you want no color, you'd say background-color:white or something to that effect.

Let's say you don't want to highlight the row, you want to make the font of that row MAGENTA (or pink or whatever color this is). You'd go:

((HtmlOutputText )col1.get(k)).setStyle("color:#cc00cc");

And that's pretty much it for the converter. Then...

2 - Register your converter in faces-config.xml
<converter>
<converter-id>TestConverter</converter-id>
<converter-class>com.foo.converters.TestConverter</converter-class>
</converter>


3 - And finally, you apply it to the first output text in the first column in your data table in your JSP:

<hutputText id="textT" value="#{vartest.FLD1}" styleClass="outputText" converter="TestConverter">
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!