• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:if

 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we have something other than EL expression inside the c:if tag?

Like this,

<c:if test="true">
Inside if.
</c:if>

or

<c:if test="10 > 5">
inside if
</c:if>

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The string inside the "test" attribute will be evaluated as a java.lang.Boolean, using the Boolean(String) constuctor.

So, test="true" will return true, because Boolean("true") will be instanciated. And according to the API:
Boolean(String):
Allocates a Boolean object representing the value true if the string argument is not null and is equal, ignoring case, to the string "true". Otherwise, allocate a Boolean object representing the value false. Examples:

So, test="5 < 6" will not be true. Because Boolean("5 < 6") instanciated a Boolean object set to false.
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:if test="true">
Inside if.
</c:if>

//The output is Inside if

<c:if test="false">
Inside if.
</c:if>


//The output is Inside if


Why it is so?..please clarify this.

Thanks.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think you hava not inserted the taglib directive to declare the taglib identified the prefix "c", so the action elements are ignored. and the page is printing the text.

add <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> at top of JSP or any library uri you are using.

Thanks
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes Narendra,it was a mistake from my side.

Thanks for correcting me....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic