This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:set with no value

 
Chris Siciliano
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1712
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty body is equivalent to specifying "" as the value of the attribute
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic