Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query regarding <c:set>

 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Need one clarification.
On page 455 of HFSJ, 2nd edition,
It is given that
Imagine that for the value (either in the body of the tag or using the value at-
tribute), you use ${person.dog}. If ${person.dog} evaluates to null (meaning
there is no person, or person’s dog property is null, then if there IS a variable
attribute with a name “Fido”, that attribute will be removed! (If you don’t specify
a scope, it will start looking at page, then request, etc.).


and on Page 457, Answer to dumb question 2 is

"If you don’t use the optional “scope” attribute in the tag, then the tag will only look in the page scope space."


I think these two are contradicting statements.

Need clarification.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This first explanation is about EL variables, and the second about a tag (which tag ?). Are you sure they refer to the same thing ?
 
Johnny Qin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of setting property, if you don't specify a scope, tag will only look in the page scope space.

In the case of removing property, if you don't specify a scope, tag will look in page, then request, and etc.

I just conclude these from HFSJ book, for your reference~
 
Larry Chung
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only an online version of HFSJ but I agree with Brij. I also see a contradiction between page 455 and 457 regarding the optional use of the scope attribute of <c:set>.
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The statement is right (although I agree its a little confusing at first). If you use the c:set tag like this
Now if ${notHere} doesn't evaluate to null, then an attribute named whatever will be created in the page scope with the result of ${notHere}. But if ${notHere} evaluates to null, then attribute named whatever will be removed from all the scopes...
 
Larry Chung
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit and Johnny. This was like one of those optical illusions where I have to stare at it long enough to realize the other perspective.

Taken out of context, what Brij pointed out did seem like a direct contradiction.
On page 455 of HFSJ, 2nd edition, It is given that
... (If you don’t specify a scope, it will start looking at page, then request, etc.).


and on Page 457, Answer to dumb question 2 is "If you don’t use the optional “scope” attribute in the tag, then the tag will only look in the page scope space."


However, the two quotes are describing two different behaviors for no specified scope attribute, the first for when the value is null and the second for when the value is not null.
This is definitely one of those clever JEE mind tricks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic