• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:if and c:choose

 
Henrik Krievs
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henrik Krievs
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic