aspose file tools*
The moose likes JSF and the fly likes JSTL c:if alternative? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSTL c:if alternative?" Watch "JSTL c:if alternative?" New topic
Author

JSTL c:if alternative?

Eric Wei
Greenhorn

Joined: Aug 09, 2011
Posts: 1
Hello!

I'm trying to use the jstl tag if, but it doesn't work. I'm sure the condition is false, but it gets into the if anyway.

<c:if test="${sickBean.description == 'ADR'}">
<a href="usuarioList.jsf" onclick="updateObjectIframe(this); return false;"> XXXX !!! </a>
</c:if>

I've searched a lil bit:

With Facelets, JSTL evaluations happen at compilation time, whereas other EL evaluations happen at render time. This means that the majority of the time, JSTL does not do what the developer intends. Unless they know JSTL quite well.


Uh.. and most people suggests to use the rendered atribute, but that's not my case.
What are the alternatives for the c:if ?

Thanks in advance!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

The primary alternative to the "c:if" tag is the "rendered" attribute, since most other conditional expressions covered by the JSTL "if" tag have no business on the View definition. A JSF View is not a JSP, even when you give it the ".jsp" extension - it's a template.

The problem is you're using brute-force HTML. I don't recommend mixing HTML and JSF either, but it's far less likely to cause actual malfunction than JSTL does. Use the JSF "hutputLink" element and you can slap a "rendered" attribute on it no problem.

Speaking of keeping the MVC implementation clean, I also recommend not coding any complex or business-related logic into EL. Put the logic in a backing bean and expose the results as a property. For example, instead of
code]
test="${sickBean.description == 'ADR'}"
[/code]

do
[code]
rendered="#{sickBean.describedAsADR}"
[/code]

Pair this with an "isDescribedAsADR" method in sickBean and you'll keep your maintained logic all in one place and not have to play hide-and-seek to find while file the logic is in when the codes change.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL c:if alternative?
 
Similar Threads
Help with the SignUp page
logic tags in JSTL?
EL and JSTL
EL: using variable within an array-variable
jstl c:if problem - surely this is impossible?