File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting the Style Dynamically

 
Fezekile Futhwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am completely new to JSF.

I am rendering a dataTable with several columns, a few columns must display different styles based on column data.

E.g.
<p:column headerText="Monday" style="width:100px" styleClass="">
<hutputText value="#{rowVar.monday}" />
</p:column>
<p:column headerText="Tuesday" style="width:100px" styleClass="">
<hutputText value="#{rowVar.tuesday}" />
</p:column>
<p:column headerText="Wednesday" style="width:100px" styleClass="">
<hutputText value="#{rowVar.wednesday}" />
</p:column>

I want to set the styleClass property to different styles based on the value of #{rowVar.*}. Like:
if (#{rowVar.*} == "A")
bold
else if (#{rowVar.*} == "B")
italic
else
normal

I have difined the styles at the top of the page. How do I evalute the condition in the styleClass property?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Javaranch, Fezekile!

You can use EL expressions to retrieve style information for column definitions from a backing bean property. That's assuming that you really wanted to define the style for the whole column. If you're looking to style individual cells based on their contents, that's a different matter.
 
Fezekile Futhwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

Unfortunately the styles are set at cell level! So far it works fine for two or less, but am trying to figure out how to do it for more than two cells.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to do it is to wrap the cell in a 1x1 panelGrid. I'll forgive you if you find this overkill and use a div element as a wrapper, though. You can use EL as a div style expression thanks to a loophole in how EL works on a JSF View.

However, to control appearances on a cell-by-cell basis, you're going to have to have a property in the tablemodel row to return the style of that cell, which means that your actual tablemodel row class may need to be implemented as decorator for the underlying data instead of using the underlying data directly.
 
Fezekile Futhwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmm, I hear you. I had expected this to be a simple thing!!

But it seems like I may have to rethink my implementation then..... thanks though.

ps: As an afterthought, is there any particular reason why JSF does not lend itself to being parametised? This would have been so simple, if only I could call a JavaBean with a parameter(s)!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fezekile Futhwa wrote:

ps: As an afterthought, is there any particular reason why JSF does not lend itself to being parametised? This would have been so simple, if only I could call a JavaBean with a parameter(s)!


Because JSF isn't a "programming" environment, it's a Model/View/Controller environment and Views are supposed to be display definitions, not executable code. And, for that matter, you can't "call a JavaBean" anyway - you invoke a method defined for that bean - if you want to be pedantic about it.

JSF2 is a little more amenable to View parameterization than JSF1 was, but people often abuse the privilege.
 
Fezekile Futhwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay......I had assumed more options for the conditional operator than is available.

I have been liking JSF very much so far......!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic