• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why do we need ActionForm ?

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we not use html instead ? I know that Action form provides validate and reset methods,however we have reset in html and also validation logic can be provided in the execute method of our action class rather than in ActionForm. So why use ActionForm ?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't have ActionForms, then where will be the form data that the users fill up go?? You'll have to manually extract all the request data from the request object. ActionForms transfer all the data themselves. Coming to validation, having validation logic in execute method isn't a very good idea. Validation logic should be reusable. Also if you validate everything inside the execute method, you'll have to manually send the request back to the input page if validation fails. I don't like the idea of ActionForms too much, but if you are using Struts 1.x, then you have to use them to get form data automatically...
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response.
Here in the below code we are not instantiating the ActionForm (user) , any idea why we CANNOT create instance of ActionForm ? If we do not create instance then how are we calling the methods ?

User userForm = (User)form;
String user = userForm.getUserId();


Thanks
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The execute method takes an ActionForm as one of its parameters. You don't have to create it because you already *have* it.
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
User userForm = (User)form;
String user = userForm.getUserId();

Somewhere someone would be creating an instance of "User" as per above code. Is it RequestProcessor ? or ActionServlet ??

Sorry for repeating this question again. Just wanted to get a clear understanding of "whats happening in the background". Thanks.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forms are created by the RequestProcessor. The implementation of the form is determined by the form definition in the struts-config file.
 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this http://struts.apache.org/1.x/apidocs/org/apache/struts/action/ActionForm.html
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David Newton,

Just would like to clarify that its the ActionServlet NOT RequestProcessor that creates the instance of Action and ActionForm (please refer pg 257 of Struts in Action). I happened to read it over the weekend.

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code is from the default RequestProcessor, from Struts 1.2.7 (circa mid 2005):The comment where it says "Create the form" is where the ActionForm instance is created (or retrieved from session).

SiA covers Struts 1.0 and 1.1, which have been dead and buried for years. If you're asking for historical information, just note it in your questions, otherwise you're likely to get current, useful information.
 
reply
    Bookmark Topic Watch Topic
  • New Topic