File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:set var question

 
Yogesh Hingmire
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i use a <c:set var = "Fido" value = null/> and i have two attributes one in page and other in request scope.
Would the execution of this tag remove the Fido attribute from page scope as well as the request scope?

Thank You
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can say value=null. And if you say value="null", well you'll get a String with the characters n, u, l, and l.

value="${null}" might work.

It will only change one scope's value - the first one it finds. Since you did not specify a scope, it will first look in the default page scope (which it finds) and that should be the only one effected.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can say value=null
No, indeed not! If you want to remove something from a scope, use <c:remove />:In that case it'll remove the attribute called "Fido" from all scopes (by the semantics of PageContext's removeAttribute method).

Back to your original question, if you use:The value of the "Fido" page-scoped attribute will be set to "SomethingElse", overwriting any previous value stored in that attribute. It will only affect the page scope here as you haven't supplied a scope explicitly. <c:set /> operates according to the semantics of PageContext's setAttribute method when no scope is supplied.
 
Yogesh Hingmire
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc/Charles.
I understand, that <c:remove> is the way to go for attribute removal, but my question is HFSJ mentions that <c:set has the effect of removing an attribute from a scope, when you set it to a ${null} value.
From Marc's answer it seems it will only remove the attribute from the first scope it finds it in.
so say for eg : if i have this :

<c:set var = "Fido" value = "${null}"/>.

I have Fido in request and session scope.

per Marc, it will only remove the attribute in request scope and not the session scope.

Please let me know if my understanding is correct.

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

<c:set var = "Fido" value = "${null}"/>.

This tag removes all the attribute Fido from all scopes.

If the attribute scope is specified, the scope variable is removed according to the semantics of PageContext.removeAttribute(varName, Scope). That is the attribute is removed from particular scope.

If the attribute scope is NOT specified, the scope variable is removed according to the semantics of PageContext.removeAttribute(varName). That is the attribute is removed from ALL scope.

Alternately, As per Charles said, you can use

<c:remove var="Fido" />

for the same effect.


Thanks
[ July 28, 2006: Message edited by: Narendra Dhande ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That didn't sound right to me, so I had to test it.

The reason it didn't sound right is that when you use c:set to replace a value without specifying scope it will only replace the first one it finds. Why should a value that evaluates to null act differently? But it does!


That code gave this output:
aaa bbb ccc ddd --- zzz bbb ccc ddd --- ---

Totally weird!!!
[ July 28, 2006: Message edited by: Marc Peabody ]
 
Yogesh Hingmire
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Narendra/Marc,

Can we conclude that <c:set> behaves differently when you set by specicfying some value as opposed to when you set by specifying an expression that evaluates to null ?

Yogesh
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I believe my test proved that.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc for your testing result,

I had not tested the <c:set> behaviour for null values. But I read it from the JSTL 1.1 spec. There is one seperate para on this behaviour.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic