wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Reusability of ValueObjects in Struts" Watch "Reusability of ValueObjects in Struts" New topic
Author

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 used...in short is it possible to do lazy loading of the formobjects and using it.
Rishi Singh
SCJP,SCWCD
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
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
Author
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="http://husted.com/struts/book.html" target="_blank" rel="nofollow">Struts in Action</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reusability of ValueObjects in Struts
 
Similar Threads
saving hidden fields in Action Forms
prepopulating html forms
struts validation repopulate arrays, arraylists
Struts : reset method
request submission struts/jquery