Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

c:set var  RSS feed

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reference HFSJ Pg 445

"If the value of the object is null, the attribute is removed. (If scope is not specified it will start looking at page, request, and so on)"

Now if it does find an attribute at page level, i thought only the page level attribute is removed.

It came as a surprise to me that the attribute at all levels is removed.



Output
Print set values
>com.example.bean.MyBean@8fbecf<
>request<
>session<
>application<
Print new values
><
><
><
><

Is this a bug or it is supposed to work this way?
Using Tomcat 5.5.23
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If attribute scope is specified, the scoped variable is removed according to
the semantics of PageContext.removeAttribute(varName, scope).
Otherwise, the scoped variable is removed according to the semantics of
PageContext.removeAttribute(varName).


And if you look at PageContext.removeAttribute(varName) : Remove the object reference associated with the given name from all scopes. Does nothing if there is no such object.

So if you don't specify the scope, and the value is null, then the variable will be removed from all scopes.
 
swarna dasa
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!! Should have looked at the API docs
Thanks though!!!
 
swarna dasa
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Add-on

In the above jsp if we have a c:set without value, then only the pagescope is affected


Output is

><
>request<
>session<
>application<

if value is not provided then is the value considered to be an empty string as against null?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!