In keeping with MVC there should not be any business loic in the form bean.
Therefore the action class should be responsible for populating your form
bean. Also, the main purpose of reset() in the form bean is to clear the
form's fields before the post() method populates it with the user's input.
Reset() is invoked automatically by struts. Specifically you cannot detect
changes to checkboxes unless they are reset first.
----- Original Message -----
From: "Mattias Norlander" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 19, 2002 8:52 AM
Subject: Design question on loading form data
> Hello!
>
> If i want to fill a form with data (from, say a database) before showing
> it to the user: Can this be done in reset() method of the form, or should
> it be in the perform() method of the action class?
>
> I think that doing it in the reset() method produces the cleanest code.
> This can be done in quite a dynamic way too, since the reset method has
> access to the http request and the mapping. It can use these to get info
> on what (if any) item to load from the database.
>
> Short example:
>
> <--------------------------->
> I have an action called editOrder and a form called orderForm.
> In the reset method of the form:
>
> reset(mapping,request) {
>
> // check mapping, the form might be used by other actions
> // that don't want our little featue
> if (mapping.getType.equals("editOrder") {
> int orderId = request.getInt("orderId");
> OrderData order = db.loadOrder(orderId);
> this.orderName = order.getName();
> this.orderSize = order.getSize();
> // .. and so on
>
> }
>
> }
> <--------------------------->
>
> Any suggestions or thoughts around this way of doing things? Looks nice to
> me,
> but I'd sure like to know if there is something nasty that I've missed
here.
>
> Regards,
>
> Mattias Norlander
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>