File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes form bean scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "form bean scope" Watch "form bean scope" New topic
Author

form bean scope

Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
Hello Friends,
We have one issue form bean scope in our applicatoin
1. We have extended the validation form for the form bean class

2. In the action tag, we havent specified any scope attribute.
3. Once i trigger the action
4. inside action class, i just get the form from action argument
and set some values

I tried printing in the jsp
${pageScope.promotionForm.channel} (channel is one property in the form bean)
${sessionScope.promotionForm.channel} - i cud get value here

Question
1. I havenmentioned the scope attribute in the actiontag. How come the form is kept in session.
2. Default value for the action tag is request rite?


Can anyone please clear

One more question
1. Can anyone tell me clearly wht happens when a form submitted andaction called. how the parameter values are set to form bean.
Does the logic involves findAtrribute method without anyscope?


Karthik R


SCJP 1.4 SCWCD 1.4 SCDJWS 1.4
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Karthik Rajendiran:

2. Default value for the action tag is request rite?

Wrong. If you don't specify a scope for an action, it will default to session scope. You've already demonstrated this in the above code.
Originally posted by Karthik Rajendiran:

Does the logic involves findAtrribute method without anyscope?

No. When a form is submitted, the Struts RequestProcessor first finds the action mapping defined in the struts-config.xml file and determines what the scope of the action is. As we've already established, if you didn't specify a scope, the scope is session. Struts then checks to see if the form bean exists as an attribute in the specified scope. If it exists, it is used. If not, Struts instantiates a new bean and puts it in the scope. Struts then goes through it's process of populating the form bean by calling the setters on the bean.


Merrill
Consultant, Sima Solutions
Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
Thanks Merill. You are correct.
How many instances of form bean are created generally.
If there are multiple actions referring single form bean
How many instances are created.

1.I have one action without any scope attributed referring form bean A
2. I have another action i have scope as request with same bean A

I could see there are two attributes being created one in rquest and another in session.
Does it work that way?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Karthik Rajendiran:
I could see there are two attributes being created one in rquest and another in session.
Does it work that way?

Yes, it does. That's why specifying different scopes for the same form bean is a bad thing and should be avoided. It leads to confusion and sometimes unexpected results.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: form bean scope