• Post Reply Bookmark Topic Watch Topic
  • New Topic

hi light a perticular row in jsf datatable

 
deepak londhe
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to light a perticular row in jsf datatable and change color of that row when selected.
 
Tammy Easterby
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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:

<hutputText id="textT" value="#{vartest.FLD1}" styleClass="outputText" converter="TestConverter">
 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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.

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

This is just one of the way to do it.

Thanks

Sajan Patel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!