File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes c:if and c:choose Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "c:if and c:choose" Watch "c:if and c:choose" New topic
Author

c:if and c:choose

Henrik Krievs
Ranch Hand

Joined: Jan 05, 2004
Posts: 59
Must c:if/c:choose have an EL as test parameter ? In HF all examples uses EL. Isn't it possible to write something like <c:if test="1 < 2"> ?

Rgds, Henrik
pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
what is test="1 < 2" ???

it just evaluates to null and its treated as false by default

<c:if test="1 < 2" var="x"/>
result is:${x}

this evaluates to result is:false


Thanks,<br />Pallavi
Henrik Krievs
Ranch Hand

Joined: Jan 05, 2004
Posts: 59
I'm sorry but I really don't get it.

<c:if test="1 < 2" var="x"/>
result is:${x}

Output: result is:false

But that doesn't proove anything. 1 < 2 - usually resolves to true ;-)

What I want to know: Is it possible to put anything than EL in the test attribute AND make it work ?

Rgds, Henrik
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy--
Good question... we discuss this a little on page 471.
Here's the deal: inside <c:if>, for example, in the JSTL spec, it tells you that the attribute type of *test* is <rtexprvalue>true</rtexprvalue>.
So... means it can be one of three things;

* EL expressions ${whatever}
* Scripting expressions <%= request.getAttribute("whatever") %>
* <jsp:attribute>

So, to answer your question, you CAN have more than just EL when the attribute type is defined as <rtexprvalue> (otherwise, it must be ONLY a static String value).

So, that means that ANY place you see us using EL within an attribute value for a JSTL tag, you know that the rtexprvalue must be true, which means you can also use regular scripting expressions or a <jsp:attribute> in addition to EL.

cheers,
Kathy
Nitish Bahadur
Ranch Hand

Joined: Aug 25, 2003
Posts: 118
I think we missed the $ in the test.

<c:if test='${1 < 2}'>
this is true.
</c:if>

<c:if test='${2 < 1}'>
this is false.
</c:if>
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: c:if and c:choose
 
Similar Threads
HOW: 'if'-like JSF conditions?
c:if
JSP Struts/JSTL Form problem
Problem with JSTL
Content of JSTL test attributes