Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

c:if inside a table  RSS feed

 
James Greenberg
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I have a <h:dataTable> (running on GlassFish v2ur2), where a column should display the price unless it's not empty (the price's string length >= 1):

The problem is that the <c:if> works weird, it doesn't print anything, regardless of whether the price's string length is greater than 1 or not:


I'm afraid it could be some JSF/JSP interoperability issue, I would appreciate any comments.
[ November 15, 2008: Message edited by: James Greenberg ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the HTML source ?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not good practice to do logic or string functions on a JSF page.

One of your problems, I believe, is that you're attempting to perform an implied string concatenation by placing multiple items in an EL expression:

value="#{msg.price}: #{item.price} #{item.currency}"

Here's a more JSF-friendly way to do it:



I replaced the explicit style with a class name because it's recommended CSS practice, but that's just being pedantic. If I wanted to be ideological as well, I'd have wrapped the "br" tags in <f:verbatim> tags, but that's probably not going to hurt here.

Notice I replaced your page logic with a custom property which is the formatted version of your expression. Its implementation, and the method that determines whether the object is rendered, are given below.

A note: JSF is extremely sensitive to element definitions. So much that even XML comments can throw off table rendering (I think there's a fix planned for that one). Which is one very good reason to use JSF tags instead of external rendering control logic.

Anyway, here's the added methods:



Youre'referring to 2 different objects (item and price), and "this" refers to the "item" bean, but in reality you may want to arrange things differently.

The Format class is very useful, especially if you want fine-grained control over message formatting. It works well with I18N.
[ November 17, 2008: Message edited by: Tim Holloway ]
 
James Greenberg
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot both of you,
as it turns out (I've done some tests), the JSP code is evaluated first, this makes a lot of difference in my case as I thought the page just executes from top to bottom regardless, that's why my code executed in such a weird fashion.
My problem was/is: I (once again) underestimated the (golden) rule: never ever mix JSP and JSF code inside the same file if you don't wanna spend days/weeks later debugging.

SO I replaced the JSP code with the JSF counterpart and anything works fine.. so far..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!