Hi, I just started using struts. And like you, I thought creating all the extra Action mappings and Action objects would add extra complexity. So I created an enhancement request asking that a new method be added to the ActionForm object which would be called when the ActionForm is created. This method would be passed the HttpRequest which caused the ActionForm to be created so that the ActionForm could use the HttpRequest object to pre-populate itself without the need for a separate action.
But someone in struts-dev mentioned that ActionForm.Reset() is called after an ActionForm is created in addition to being called just before HTML form values are populated to the ActionForm's properties. This was great because it provided the functionality I was looking for. So basically what happens is that when an <html:form> element is referenced in the JSP, the ActionForm which matches the <html:form>'s "action" property gets created if it doesn't already exist. Since you know the first call to reset() corresponds with the creation of the ActionForm object, you can do all your initialization. Then when the JSP continues on to render other fields in your form, they will be populated with good data. I tried it out and it worked great. I didn't have to make any Action objects just for the purpose of initializing ActionForm objects. I just let the ActionForm objects take care of it themselves on the first call to reset(). I also configured struts to keep the ActionForm on the session scope so that the ActionForm wouldn't have to go through an extra initialization when the user actually clicked the submit button on the form rendered by the JSP. The only thing that worries me is that the behavior of calling ActionForm.reset() upon ActionForm creation is not documented so I'm a little worried that future versions of Struts may change this behavior. But taking advantage of the current behavior makes prepopulating forms allot easier so I'll take my chances. What can I say, I'm lazy :) Kurt -----Original Message----- From: Ajay Patil [mailto:[EMAIL PROTECTED] Sent: Friday, July 11, 2003 6:21 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Populating form from request parameters in JSP Thanks Nagi, Atleast I know that I am not doing something wierd. Anyway, why does the JSP page care about the origin of the forward. Why cant it simply autopopulate the form from request parameters ? Defining an extra action class just to do the forward seems to unnecessarily increase complexity. What do you think ? Ajay hi, your two jsp pages have different action forms associated with them. so u cant expect the second jsp page to autopupulate the previous request parameters. u have to go thro' the struts thing(action class) which will then autopopulate ur new action form and then the jsp page associated will show the values.. if both ur jsp pages share a single action form(which is in session) then the second jsp page will automatically show the values hope its clear now -- nagi -------Original Message------- From: Struts Users Mailing List Date: Friday, July 11, 2003 12:33:32 PM To: [EMAIL PROTECTED] Subject: Populating form from request parameters in JSP Hello, I know this question has probably been asked several times. But, possibly a Struts developer can explain because I am confused. Generally, my action classes receive posted data, query the database, put the query result as request attribute and then forward to the next JSP. However, I find that form properties in the next JSP dont get auto-populated from the request parameters. So, I define a new action class (associated with the next form), and use it simply for forwarding. And then I can see the form properties auto-populated. So, why is this extra step (or extra action class) needed ? Or am doing something wrong here ? Please clarify, Ajay --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]