This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean in or out scope?

 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code below






what i had expected below,

default
new

the jsp page responded below,

new
default

Why?


 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I understand why,

at the time the <jsp:setProperty name="b" property="p" value="new"/> is executed, there exist two beans named b. One in request scope the other in session scope.

setProperty tag does not accept scope attribute so it starts to search through all scopes starting with page scope, then request scope and so on. It sets the property of the first bean found.

In your example it sets the "new" value to the bean in the request scope so the bean in session scope is left uninitialized.

[ January 08, 2007: Message edited by: Jasiek Motyka ]
[ January 09, 2007: Message edited by: Jasiek Motyka ]
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jasiek

i also tried out myself, in short,

- set/getAttribute methods: always scoped
- jsp:useBean: always scoped
- jsp:set/getProperty: scope order from request, session and likewards
- EL bean without scope prefix, scope order from request, session and likewards
- EL bean with scope prefix, always scoped
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp:set/getProperty: scope order from request, session and likewards


Can anyone tell the complete search order
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scopes are searched from the narrowest to the widest. From page scope, request scope, session scope to the application scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic