On Wed, 12 Dec 2001, Jon Burford wrote:

> Date: Wed, 12 Dec 2001 20:40:34 -0800
> From: Jon Burford <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: form initialization
>
> Greetings!
>
> I have a dynamic form which needs to be initialized from the database.
> If I put code to initialize the attributes in the default constructor
> of the form bean, all this happens with no problems - the form is
> displayed with the proper values.  My problem is that the form bean
> needs some of the request parameters from the calling jsp page in
> order to properly initialize its fields.  What is the preferred way of
> form bean initialization and how can it access request parameters at
> initialization time?  I used a couple hidden form fields which the jsp
> page initialized to the corresponding request parameters, but this
> does not take effect until AFTER the constructor is called.  Any help
> would be much appreciated.
>

This type of question is really more suited for the STRUTS-USER list.

The design pattern I prefer is exemplified in the Struts Example
application -- use an Action to set up the form bean *before* the form is
displayed.

In the example app, note how an "Edit Subscription" transaction is
handled:

* The "/editSubscription" action is called to pre-fill the
  SubscriptionForm bean and place it in request scope.  If you
  need values from the request that triggered this, they are
  accessible to the Action and it can call setters as needed.

* This action forwards to "subscription.jsp" which shows the
  pre-filled-out form.

* The submit goes to the "/saveSubscription" action which
  updates the database (assuming successful validation).

> TIA!
> Jon
>
>

Craig McClanahan



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

Reply via email to