aspose file tools*
The moose likes JSP and the fly likes c:set with no value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "c:set with no value" Watch "c:set with no value" New topic
Author

c:set with no value

Chris Siciliano
Greenhorn

Joined: Apr 02, 2012
Posts: 9
Hello !

I read in jstl spec that tag c:set with no attribute value removed the attribute specified in var properties. But i see that the container does not

removed my attribute.It just replace the oldest value by an empty string.

here my code
<c:set var="var1" scope="session"/>

It doesn't removed attribute var1. It just cleared it.

Has anybody already tested this functionality??

Thank's


SCJP6
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18902
    
    8

Chris Siciliano wrote:Has anybody already tested this functionality??


My guess is that since the spec was written 10 years ago, you aren't the first one to test it. So let's see your test.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The quote you mention relates to Syntax #1 where you specify a value attribute.
You have no value attribute specified, so this is Syntax #2, which your quoted rule does not apply to.
In Syntax #2, the value is evaluated from the body of the tag. In this case, empty String.

So this is behaving exactly as specified. If you do a set tag with a value attribute evaluating to null, then the attribute does get removed:
Snippet of JSP proving this:



(Disclaimer: Scriptlet code in this snippet is for example purposes only, to demonstrate that the attribute is indeed removed. I do not condone the use of scriptlet code in any normal JSP)
Chris Siciliano
Greenhorn

Joined: Apr 02, 2012
Posts: 9
Hi Stefan,

Thank you for your explanation.

Indeed when i put a explicit null value --> ${null} --> it removed the attribute but without value it just cleared the String.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

An empty body is equivalent to specifying "" as the value of the attribute
 
jQuery in Action, 2nd edition
 
subject: c:set with no value