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
posted
0
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:
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.
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
posted
0
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.
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.