I think this should be in the perform() method. If you look at the javadocs,
reset() is called before populating the form fields with the values received
from the HTTP request. This way you can assign default values for fields
that may be missing from the HTTP request.
This is different from the reset() action in the browser's form. When you do
a reset in an HTML form the browser just reloads whatever values were there
originally and does not perform an HTTP request. The fact that both methods
refer to forms but in different contexts is missleading eh?
Cheers,
Jorge
----- Original Message -----
From: "Mattias Norlander" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 19, 2002 9: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]>