• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

highlight a row in a datatable

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

<h:outputText id="textT" value="#{vartest.FLD1}" styleClass="outputText" converter="TestConverter">
reply
    Bookmark Topic Watch Topic
  • New Topic