wood burning stoves 2.0*
The moose likes Struts and the fly likes bean:write - scope problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write - scope problem?" Watch "bean:write - scope problem?" New topic
Author

bean:write - scope problem?

Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
Can someone please explain why <%= bean %> and <bean:write name="bean" /> give different results in the simplified code below.
<jsp:useBean id="menuFactory" scope="application" class="menu.MenuFactory" />
<jsp:useBean id="menu" scope="session" class="menu.Menu" />
<% menu = menuFactory.getMenu("menu2"); %>
<%= "1 " + menu %><br>
2  <bean:write name="menu" /><br>
gives this output
1 Menu:menu2
2 Menu:null <-- why null and not menu2?
I thought <bean:write> searched all scopes?
Rich
Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
I've got my answer!
Turns out <jsp:useBean> as I used it, creates an instance of my bean (since none exists) and creates *2* references to it: one reference is stored in the session scope and is used for all the get/setProperty operations, the other reference is used as a scripting variable and has page scope. In my example code, when I assign a new value to the scripting variable the variable in session scope still has a reference to the bean created by <jsp:useBean>. Voila! now I understand my results.
Rich
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write - scope problem?