File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reusability of ValueObjects in Struts

 
Rishi Singh
Ranch Hand
Posts: 321
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ted Husted
Author
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic