• 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

Finding Session Object?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using Struts for a J2EE 1.4 application. On the server side, I have to initialize a Strut form's values/fields BEFORE the associated Action is called. The way the lead tech has designed the architecture, this is my challenge.

The only way I can initially see how to handle this is to load the form's values as part of a constructor for the form. However, I don't know how to reach the session object.

Is there a way to call the container and receive a collection of objects, do a search for instanceof session and then retrieve the needed ejb from there?

Thanks for your help in advance!!!

JD
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first: i'm not an expert in this constellation. but as far as i recall it is NOT the case that you have one ActionForm instance per request. This is handled transparently by the Struts request processor. which obviously means that you cannot place code in constructors which do a individual setup.

also - if a form does the client server roundtrip, struts will call getters and setters BEFORE the action is called. i would rather go with the (struts) achitectural intention and work with forms from within actions.

long talk short sense - looks like a terrible bad idea in my eyes. maybe merrill has some comments too...

good luck,
jan
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, I disagree with your lead tech's approach. ActionForm beans were designed to be simple beans that carry data to and from a page. Struts was designed so that Action classes do the actual work of manipulating the data in ActionForms.

Having said that, there is a way to accomplish what you want. ActionForm has the following method that you can overrride:



This method is called after an ActionForm is created, but before any of its setters are called if a form is being submitted. Since you are passed the request as a parameter, you can use it to get the session and do whatever you want with it. I'd suggest a lazy initialization approach where you check to see if the data is null, and if it its, initialize it.
 
JD Thompson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan and Merrill,

Thank you both for your thoughts and suggestions!! I agree the situation is less than ideal but you have definitely helped me out in terms of having another plan of attack (i.e. overriding the reset method).

I will let you know if success is reached!

Take care and have a great weekend!!

JD
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to wonder how much Struts development experience your lead tech has. When you say "BEFORE the associated Action" what do you view as the "associated Action"? Are you talking about initializing data before the initial page is shown or after the user clicks the submit button but before your execute method?

For a general form type page I almost always have an action that is used to display the page. The role of this action is to initialize default form values in the case of an "add" and to populate the form values in the case of an "edit". Would this work for you?

- Brent
 
reply
    Bookmark Topic Watch Topic
  • New Topic