• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

hi light a perticular row in jsf datatable

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to light a perticular row in jsf datatable and change color of that row when selected.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

I asked this same question before and nobody responded.

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">
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JSF, all TAGs can take expression language e.g. #{vartest.boldStyleClass}.

So you can do following also and pass style class name from Object itself that what style you want to use it.

<h:outputText id="textT" value="#{vartest.FLD1}" styleClass="#{vartest.boldStyleClass}" converter="TestConverter">

This is just one of the way to do it.

Thanks

Sajan Patel
 
reply
    Bookmark Topic Watch Topic
  • New Topic