aspose file tools*
The moose likes Struts and the fly likes DynaForm vs ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DynaForm vs ActionForm" Watch "DynaForm vs ActionForm" New topic
Author

DynaForm vs ActionForm

Ankur Srivastava
Ranch Hand

Joined: May 11, 2004
Posts: 62
Hi All

I would like to know the difference between DynaForm and ActionForm and also about the resources which tell me in details about the new features in Struts 1.1 compared to 1.0

Thanks in advance.
John Carnell
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 71
Hi Ankur,

An ActionForm holds form data submitted from a request. As a developer you extend the ActionForm class and provide your own implementation of it. You have to physically write get()/set() methods for each of the attributes you are collecting from the form.

A DynaActionForm is a declarative model. With a DynaActionForm you declare the attributes you are collecting from the web form as an XML declaration in the struts-config.xml. DynaActionForms work well if you are just collecting data and using the basic validation rules that come with the Validator framework.

They are easy to setup and you can add/remove attributes without having to modify your code. I hope that answers your question.

Thanks,
John


John Carnell<br />Principal Architect<br /> <br />Netchange, LLC<br />1161 HillCrest Heights<br />Green Bay, WI 54313<br /> <br />john.carnell@netchange.us<br /> <br /> <br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/159059228X/ref=jranch-20" target="_blank" rel="nofollow">Pro Jakarta Struts, Second Edition</a>
Ankur Srivastava
Ranch Hand

Joined: May 11, 2004
Posts: 62
Hi John,

Ya that has very much answered my question. Thanks for the prompt reply. But can you tell me is the validation framework also declarative, that is I do not have to write the validate method.

Surely it must be otherwise where will we write a validate method as we are not writing the ActionForm classes. But then does it support Regular Expressions and what about complex validations.

Thanks again
Ankur
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Ankur Srivastava:
can you tell me is the validation framework also declarative, that is I do not have to write the validate method.

Surely it must be otherwise where will we write a validate method as we are not writing the ActionForm classes. But then does it support Regular Expressions and what about complex validations.

There's a method
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request);
defined in the ActionForm base class, which you can override in order to implement form validation.

However, there's also the Struts Validator which is a declarative validation framework (with validations specified in an XML file).

You can read more about the Struts Validator in the Struts Validator Guide.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Karl Beowulph
Ranch Hand

Joined: May 31, 2004
Posts: 130
I think I should add that dyna forms seems to be a bit more prone to trouble with your IDE.

If you're using Eclipse and JBoss they can sometimes cause errors for no real reason .

In my case, everytime I change a dynaform, I have to delete several xml files, shut down Eclipse, start it back up, and run XDoclet.

If I don't do that, I'll keep getting "Invalid Property Name" errors.

I suggest that you start with dyna's and if they give you problems, test out the same form as an ActionForm.
Srinivas Rao
Greenhorn

Joined: Aug 05, 2004
Posts: 14
This will given me the basic difference between both the type of forms. Can any one suggest where we can use each of one? If any one explains with some example it is more clear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DynaForm vs ActionForm
 
Similar Threads
Performance comparison of ActionForm and DynaForm
Advanatages of DynaActionForm over ActionForm
How can I change the value of a bean ?
Pro Jakarta Struts, Second Edition : Reader Question
How do I do this, input field retains value