• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

form bean scope

 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Karthik Rajendiran
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic