Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clarification with c:set

 
A. Aka
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am reading head first (2nd edition)and I am confused.
for c:set :

if the value is null, the attribute named by var will be removed by starting looking at page, request, session if the scope is not mentioned

but if the value is not null, the default scope is page

right ?

page 455 (bang) and 457(key point and gotchas with c:set)
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2333
86
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aka,

if the value is null, the attribute named by var will be removed by starting looking at page, request, session if the scope is not mentioned
but if the value is not null, the default scope is page


Correct, just have a look at the specs jstl 2.2:
4.3 <c:set>
Syntax 1: Set the value of a scoped variable using attribute value
<c:set value="value" var="varName" [scope="{page|request|session|application}"]/>

Syntax 2: Set the value of a scoped variable using body content
<c:set var="varName" [scope="{page|request|session|application}"]>
body content
</c:set>

Syntax 3: Set a property of a target object using attribute value
<c:set value="value" target="target" property="propertyName"/>

Syntax 4: Set a property of a target object using body content
<c:set target="target" property="propertyName">
body content
</c:set>

Syntax 5: Set a deferred value
<c:set var="varName" value="deferred-value"/>

If value is null
Syntax 1: the scoped variable defined by var and scope is removed. If attribute scope is specified, the scoped variable is removed according to the semantics of PageContext.removeAttribute(varName, scope). Otherwise, there is no way to differentiate between syntax 1 and syntax 5. The scoped variable is removed according to the semantics of PageContext.removeAttribute(varName), and the variable is removed from the VariableMapper as well.


Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic