File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Reusability of ValueObjects in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Reusability of ValueObjects in Struts" Watch "Reusability of ValueObjects in Struts" New topic

Reusability of ValueObjects in Struts

Rishi Singh
Ranch Hand

Joined: Dec 09, 2000
Posts: 321
Hi All,
As per the framework the ActionForm is created by the RequestProcessor once it initializes and gathers mapping information from struts-config.xml.The ActionForm is created for every request and it is cached and the properties are reset for the next request.Now if there is a Java Bean with ten public fields and corresponding accessor methods, now if out of these if next request consists of four fields which are part of the previous request, can the same Form object be short is it possible to do lazy loading of the formobjects and using it.
Rishi Singh
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
Lazy loading? What exactly do you mean?
The formbean can be stored in the request or in the session, which you configure yourself. If you put it in the session, the old formbean with its values will still be there when the new request comes in, and so the new request will use the old formbean.

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Ted Husted
Ranch Hand

Joined: Dec 02, 2002
Posts: 37
You can specify whether an ActionForm is placed in request or session scope. If you place it in session scope, you can just fill up the form a request at a time. If there is a corresponding parameter in the request, the property is populated. Otherwise it is ignored.
If you choose to use request scope, then each form must carry the properties forward using hidden fields.
Generally, I recommend using coarse-grained ActionForms with as many properties as you need for the application (or a group of related forms in a very large applications). This avoids having to maintain the same properties in multiple classes.
If you are using your own validations, you can subclass the base ActionForm and provide a validate for each distinct set of data.
If you are using the Struts validator, you can just define a formbean element for each distinct validation. The Validator doesn't look at the ActionForm class, but the form-bean name.
HTH, Ted.

<a href="" target="_blank" rel="nofollow">Struts in Action</a>
I agree. Here's the link:
subject: Reusability of ValueObjects in Struts
jQuery in Action, 3rd edition