• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

findAttribute method of pagecontext

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

The following is from David Bridgewater's book...

"This is the most interesting method. You merely pass in an attribute
name, and the method works through the scopes in order:
page, request, session, and application. The first attribute found is
returned; consequently, an attribute in a more local scope (such
as page) will �shield� one of the same name in a less local scope
(such as session), so you can use this method only to get the most
local attribute value when names are duplicated across scopes
. For
this among other reasons, I try to keep my attribute names unique
across scopes unless there is a very good reason to do otherwise."

I'm not able to get the part in bold?? Any help guys?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, which parts do you understand? Are you familiar with the various scopes? Can you describe to us the differences between them? What happens if you have an attribute named "results" in the request scope, and one named "results" in the application scope? That's what the paragraph is talking about.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

I understand the three scopes but as I mentioned in my post what is the literal meaning for the bold part. Does it mean that local scope is more easier to find and returned when there is an attribute with such a name??
 
Tanveer Ahmad
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its like this... say you have an object of Dog in all four scopes with same key "SPIKE"... now if you say findAttribute for "SPIKE"... you will get the one which is there in Page scope. if you remove SPIKE from page scope and you try again finding the SPIKE then this time you will get it from request scope and so on. Hope I am clear.

Tanveer
 
Tanveer Ahmad
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And it has nothing to do with easy or hard... findAttribute is designed to start finding the attribute from page scope - request scope - session scope - app scope. the moment the attribute is found search is stopped.

Tanveer
 
Saurabh Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and that would simply mean that if you have an in all the 4 scopes: page, request, session and application and you use findAttribute() to find this attribute; you will get the one in "page"(more local). In this case,you won't get the attribute from request/session/application scope(attrinute in less local scope shielded by the one in more local scope).


Thanks and regards,
Saurabh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic