struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Pelly <>
Subject Prepopulating Form elements in ActionForms
Date Thu, 10 Mar 2005 19:51:11 GMT
I am having trouble with the ActionForm reset() method. I am using the
method to handle prepopulating form values.  My Struts app uses the Struts
Validator's DynaValidatorForm (which extends ActionForm via the
DynaActionForm class).  I am attempting the following behavior in a class I
call "BaseActionForm":

1. Prepopulate form values in the reset() method of BaseActionForm.
2. When the JSP is submitted, if no value has been populated for a variable
named "ptn" (and if other criteria are true), return to the original JSP
(via an action-mapping) and display an error message, plus show the form
inputs the user entered (not the prepopulated defaults).

The problem I run into is that the reset() method seems to be populating my
DynaValidatorForm before the page is loaded and after as well.  

I want the reset() method called beforehand - this prepopulates my form
values.  However, when DynaValidatorForm.reset() is called after the form is
submitted, it is "re"-prepopulating the submitted form with defaults, the
result being that if the user erases a prepopulated value, the ActionForm
repopulates it with the default.  In other words, a value of "foo" was
prepopulated, the user erases that value and submits, the form prepopulates
it again with "foo" (bad!) and passes control to the action.

I also want to make sure that if the form elements have been incorrectly
populated, when the form returns to the JSP, it has not clobbered the
user-supplied (albeit incorrect) empty form values.

I have tried adding a check in the ActionForm (if super.get("ptn") is ""),
but it seems that this check always returns true from within the
ActionForm's reset() method.  It appears that the ActionServlet populates
the form after it calls reset().

I have done the usual web searches but have not found any good resource that
explains the proper way to use reset() or handle form prepopulation using
Struts.  I am aware that the reset() method is primarily intended for
checkbox prepopulation (only), but I do not know of a better way to handle
the above issue.  I used this approach because it was recommended in
Apress's Pro Jakarta Struts.

Can anyone provide advice or point me to some code examples/resources
(preferably using the DynaValidatorForm subclass of ActionForm, which
retrieves form element values using super.get(), as shown above)?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message