You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Boyko <ab...@fabgear.com> on 2000/11/16 19:01:01 UTC
Form bean initialization: can reset() get called by ?
We've got a form that we want to pre-fill with values
when presenting it for the first time. So we've made
an ActionForm class, whose reset() gets an ID from
the HttpServletRequest and retrieves the data to
initially populate the ActionForm's fields.
However, we want to be able to use validate() on this
ActionForm. The problem is, then, that we seem to
need two separate Actions: one that does nothing except
cause reset() to get called on the form bean, and
forwards immediately to the form JSP, and the second
action, the target of the form, which returns to
the first Action if validate() failed.
Admittedly, this isn't terrible, but it seems odd that
the first Action has no code in its perform(); the only
reason it's needed is so that reset() can be invoked on
the ActionForm. It seems to me that if the <form:form>
tag always calls reset() on the ActionForm when constructing
it, then the first Action would be unnecessary, and the form
page could be accessed directly as a JSP, submitting to the
second Action, which would return directly to the JSP if
validation failed.
I understand that the philosophy of struts would suggest that
the JSP should not be doing real work and that there should
always be an Action in a case like this, rendering this argument
irrelevant; nevertheless, if ActionForm.reset() is intended to
initialize the ActionForm to a valid initial state, shouldn't
it be invoked by the ActionForm constructor, or at least be
called when an ActionForm is created by the <form:form> tag?
probably not thinking hard enough,
Andy Boyko aboyko@fabgear.com