This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes bean in or out scope? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "bean in or out scope?" Watch "bean in or out scope?" New topic
Author

bean in or out scope?

Bob CHOI
Ranch Hand

Joined: Nov 10, 2006
Posts: 127
My code below






what i had expected below,

default
new

the jsp page responded below,

new
default

Why?




Hard work rewards
Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
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

Joined: Nov 10, 2006
Posts: 127
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

Joined: Nov 14, 2005
Posts: 324
jsp:set/getProperty: scope order from request, session and likewards


Can anyone tell the complete search order


"Know where to find the solution and how to use it - that's the secret of success."
Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
Scopes are searched from the narrowest to the widest. From page scope, request scope, session scope to the application scope.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: bean in or out scope?
 
Similar Threads
Bean standard action doubt
Doubt in jsp:useBean attribute 'type'
Help: Wrox Profession SCWCD - don't understand
problem on c:set
jsp:useBean Vs importing class file and using new