You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joey Gibson <st...@japache.org> on 2001/12/05 21:13:21 UTC

Re: RE: Populating form in the action

> 
> For instance, I create a ActionForm in the perform
> method of the Action class, and then forward the
> control to a jsp page.  How does the JSP page know
> that the form that it gets is the form that just get
> populated in the Action before?  

Don't create an instance of the form, use the one that is passed in to your perform(...) method. You will need to cast it, of course.

Joey

--
Sent via jApache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: RE: Populating form in the action

Posted by Joey Gibson <st...@japache.org>.
> The form passed in is a null because that Action is
> called the first time I type in the URL (.do), not
> after a form has been submited.
> 
> In other words, I would like to "pre-populate" the
> form before displaying it.

If you have associated the action with a form in your struts-config.xml, then any time your perform() method is executed, there should be a form instance present. I use this on my site. I do a GET on the action to, for example, edit my account record. I fetch the user record, prepopulate the form, and then forward to the jsp. Here's a code snippet:

public void perform(..., ActionForm form, ...)
{
 UserForm userForm = (UserForm) form;

 if (request.getMethod().equalsIgnoreCase("get"))
 {
   userForm.setName(...)
   // ...
 }
}

--
Sent via jApache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: RE: Populating form in the action

Posted by John Ng <jn...@yahoo.com>.
The form passed in is a null because that Action is
called the first time I type in the URL (.do), not
after a form has been submited.

In other words, I would like to "pre-populate" the
form before displaying it.

Thanks
John



--- Joey Gibson <st...@japache.org> wrote:
> > 
> > For instance, I create a ActionForm in the perform
> > method of the Action class, and then forward the
> > control to a jsp page.  How does the JSP page know
> > that the form that it gets is the form that just
> get
> > populated in the Action before?  
> 
> Don't create an instance of the form, use the one
> that is passed in to your perform(...) method. You
> will need to cast it, of course.
> 
> Joey
> 
> --
> Sent via jApache.org
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>