aspose file tools*
The moose likes JSF and the fly likes color  row-x Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "color  row-x" Watch "color  row-x" New topic
Author

color row-x

Kant P.
Greenhorn

Joined: Apr 12, 2005
Posts: 11
Hi all,
I have a bean of array. A datatable is created out of this bean. I want to be able to colo rox-x in this datatable; row-x is colored based on some business logic. How do I do that?
Example:
<h ataTable id="table1" value="#{pc_EcOutput.tableDataMrgBean.errors}" var="varerrors">
<h:column id="column1">
<f:facet name="header">
<h utputText styleClass="outputText" value="Item Number" id="text3"> </h utputText>
</f:facet>
<h utputText id="text4" styleClass="outputText" value="#{varerrors.errItem}"></h utputText>
// if (varerrors.errItem == "E1")
// styleClass="red"
//else if(varerrors.errItem == "W1")
// styleClass ="blue"
//else
//styleClass="grey"
</h:column>
-
-
-
I have tried using a wrapper class which uses those if statement above to return a particular styleClass for each errItem. Unfortunately I can't pin point the row (or row index) that contains E1 or W1 to color. It turns out coloring the whole table w/ red or blue or grey.... Can someone show me how this work please....?

Thank you for your time and assistance..
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
The dataTable has an attribute "rowClasses". Bind it to your backing bean and generate style for each row. i.e. if your normal style is "normal" and speacial one is "speecial" and you are having 3 rows in dataTable and noqw if you want the second row to be special, your rowClasses should be equals to rowClasses="normal,special,normal"

P.S. normal,special can be picked from CSS.


- Varun
Kant P.
Greenhorn

Joined: Apr 12, 2005
Posts: 11
Thank you for replying,
But the problem is if I have 100 rows...and I want row X to be color; X could be any number. Then the problem is how to find the rowIndex of X in dataTable, so I know where to color.
Others have similar suggestion like this:
<h utputText styleClass="#{varerrors.errItem eq 'E1' ? 'red' : (varerrors.errItem eq 'W1' ? 'blue' : 'grey')}"/>
But that don't work. I have also created a wrapper class to choose request color, but it come out coloring the whole table w/ one color....
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Kant P.:
Thank you for replying,
But the problem is if I have 100 rows...and I want row X to be color; X could be any number. Then the problem is how to find the rowIndex of X in dataTable, so I know where to color.


Use Table.getRowData to get the selected row and then find it's index in the collection object you have.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

To expand on what has already been said, this is going to have to be something that is done in the java code rather than the page itself.


GenRocket - Experts at Building Test Data
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Gregg Bolinger:
To expand on what has already been said, this is going to have to be something that is done in the java code rather than the page itself.


yeah, very much. It's a cleaner approach and can be centralized in a single location if one wishes.
Kant P.
Greenhorn

Joined: Apr 12, 2005
Posts: 11
Thanx all for replying again....
But i'm still struggling on how to find the selected row-x (x number is returned by a logic, so i don't know ahead of time of what it is). Here is my dataTable method in backing bean:
protected HtmlDataTable getTable1()
{
if (table1 == null)
{
table1 = (HtmlDataTable) findComponentInRoot("table1");
}
return table1;
}
I tried using table1 object to access getRowData, but nothing worked because I haven't been able to pinpoint the selected row and its index...
Can you give me more hint please?

thanks
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Probably you would like to highlight a row selected by user. Hence write an actionlistener on your row. When user clicks on any row the listener would be called and that listener will find out the row which user has clicked and hence you can highlight that row.
This logic should go in listener.
Kant P.
Greenhorn

Joined: Apr 12, 2005
Posts: 11
I got it to work.....by creating a getStyle() in back-bean of jsp page. getStyle() returns a style. Then Bind it to output text.... it works just like it want it..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: color row-x