This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes what is  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "what is  "dynamic" form bean ?" Watch "what is  "dynamic" form bean ?" New topic
Author

what is "dynamic" form bean ?

Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
In article http://javaboutique.webdevelopers.com/tutorials/strutsform/article.html
it says "the name of every control must be defined in the form's bean which may be a Java ActionForm bean or a dynamic form bean defined in form-beans of struts-config.xml)

1. What's "dynamic" form bean ? As far as I know, given a JSP page you should have a corresponding form-bean, right ? Does "dynamic" form bean map to a specific JSP page or what ?

2. Sometimes we need to create some other java beans which do NOT map to any JSP pages' form. They are just some customized java beans for business purpose. Do I need to define such beans in the "form-beans" ??


Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
1. A "Dynamic Form Bean" means using the Struts DynaActionForm or DynaValidatorForm class as your form bean instead of writing one. When you do this, you specify the properties of the bean in the struts-config.xml file. Here is a link that explains how to do this:

http://struts.apache.org/userGuide/building_controller.html
(See secion 4.3.1, DynaActionForm Classes)

2. You do not need to define other model beans in struts-config.xml. Only ActionForm beans and Action classes need to be defined there. Even if you have other beans embedded in your ActionForm, Struts finds these by reflection, and does not require you to define them in the config file.


Merrill
Consultant, Sima Solutions
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
Originally posted by Merrill Higginson:
[QB]1. A "Dynamic Form Bean" means using the Struts DynaActionForm or DynaValidatorForm class as your form bean instead of writing one. When you do this, you specify the properties of the bean in the struts-config.xml file.

So, basically I can always use DynaActionForm whenever I need an ActionForm ? And this means I save time in creating those ActionForm classes ? And it means I will NOT have any Form Bean java classes at all ?
Sounds too good!

But just wondering ---

1. Does the container automatically create a DynaActionForm instance everytime ?

2. In Action class we usually do

**********************
public ActionForward execute(mapping, form, request, response) {

SubmitForm f = (SubmitForm)form;
....
*****************

If I use DynaActionForm, should I write

**************
DynaActionForm f = (DynaActionForm)form;
**************
instead ?
Rashmini Palakurti
Greenhorn

Joined: Jun 29, 2005
Posts: 13
Yes ur right , u need not create ActionForm when u use DynaActionForms and container will create its instance just like normal ActionForm but there are some trade-offs in using DynaActionForm. It works for simple JSP's but if there are some complex validations to be done in validate() method of ActionForm then this may not be right choice.

For more about ActionForms and DynaActionForms u can refer http://www.struts.apache.org
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Yes, you lose access to validate() unless you create your own form extended from DynaActionForm but that defeats the purpose anyway and since you can create getters and setters automatically with a tool like JDeveloper DynaActionForms have limited appeal since you don't save much time using them... I don't use them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is "dynamic" form bean ?