• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

c:if and c:choose

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic