This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ?
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...
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();
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.
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.