Struts hands you a form bean in your execute method. You cast that variable to your specific form type and use the setters to move data into it. When you return an ActionForward object out of execute() struts will forward to your input form with your populated bean.

You don't have to create the form bean yourself or put it into the request, Struts does that for you as long as you tell it to in struts-config.xml.

David






From: "Iain Sanderson" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: Re: HOWTO pre-populate forms with data, then update ?
Date: Thu, 23 Jan 2003 15:43:22 -0500

David,

Thanks for your reply. How do you put the info into the form bean?

I use a action called "RegistrationUpdateOpenAction" to get the data from
the database and forward to the view jsp (registrationUpdate.jsp), but I
don't know how to put that data into the form bean for this ( the
underlying form bean would be RegistrationUpdateForm). I'm confused as the
form bean is created/recycled by Struts on opening the view. How do I get
premptive access to it? Can I just create it and add it to the request
scope? Won't struts create another one?

Iain.


Please respond to "Struts Users Mailing List"
<[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc:

Subject: Re: HOWTO pre-populate forms with data, then update ?

Traditionally you do this:
1. GetMyFormAction determines if it's add or edit from a query string
attribute.
2. For edit go get the info from db using the record's id you passed in
the
query string.
3. Put that info into your form bean.
4. Forward to your form

The form's input elements will be prepopulated with data for the edit
screen.

David






>From: "Iain Sanderson" <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: HOWTO pre-populate forms with data, then update ?
>Date: Thu, 23 Jan 2003 15:20:40 -0500
>
>Newbie question:
>
>I've managed to use Struts forms as a means of initial data entry (
>registration forms etc) but have got stuck on how to use a form to
update
>data that already exists in a database. For example, a form where a user
>can update their user details (address, email etc) and then submit the
>updates. How is this best done in struts ?
>
>I'm sure there's a good way of doing this, but my Kludge so far has been
>to create a bean in the session scope containing the data I want to
>populate the form with ( eg a user's current address), and then use
struts
> html:text tags to view the bean data using their "name" and
"property"
>attributes. Once the user has submitted their updates, the ActionForm
>accesses the form bean to obtain the updates, and applies the updates to
>the database. I then of course have to update the original bean's data
>with the new values ( eg their amended address) and send it back into the
>session scope. It's a bit of a mess, but it works.
>
>I know there's a better way. Please help. Thanks.
>
>Iain Sanderson
>


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>





_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to