You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stefan Wesner <we...@rus.uni-stuttgart.de> on 2000/08/22 17:30:15 UTC
Question on Users Guide: Multiple HTML Form into one FormBean
Hi,
I just started using struts and I finished the users guide and a small
sample app.
Now I want to do a larger Application that has serveral pages that all
together build a "project proposal".
In the users guide there is explicitely mentioned that it is useful to have
multiple HTML pages containing forms mapped to *one* ActionForm if they
belong together in order to have no dependency between the arrangement of
form elements and the actual FormBean implementation.
So I am wondering how this can be done if any of the values has to be
validated (e.g. DateFormat or required or ....) if I do not know if the user
has not specified a value or it is not within the form (but in one of the
next ones). Is there any way to detect which values have been modified/set
within the current request (beside looking into the HttpRequest on my own,
which would mean that one of the benefits of using struts will be gone).
Any more detailed examples/texts on that issue ?
Stefan Wesner.
--
Dipl.-Ing. Stefan Wesner Head of Software Technology Group
phone: +49 (0)711 685-4275 fax: +49 (0)711 682-357
mailto:wesner@rus.uni-stuttgart.de
Rechenzentrum Universität Stuttgart 70550 Stuttgart Germany
Re: Question on Users Guide: Multiple HTML Form into one FormBean
Posted by Hans Gerwitz <ja...@phobia.com>.
> So I am wondering how this can be done if any of the values has to be
> validated (e.g. DateFormat or required or ....) if I do not know if the user
> has not specified a value or it is not within the form (but in one of the
> next ones). Is there any way to detect which values have been modified/set
> within the current request (beside looking into the HttpRequest on my own,
> which would mean that one of the benefits of using struts will be gone).
A common solution to "step-by-step" validation is to have a "step" property
that is exposed as a hidden form field on each page, then the validate()
method can choose which fields to validate based on that property.
If you want a "clean" implementation that avoids the form bean having to
understand which fields are in which step, I would suggest having the bean
track which properties have been set (via setter methods that set a boolean
or add their name to a hashtable, etc); then your validate() can be "smart"
about which properties need to be set. A caveat, though: to confirm that a
page designer did not forget a field, add a "formComplete" property that is
set to true as a hidden input on the final step, and triggers the validate()
method to check everything.
Hope that helps,
--
Hans Gerwitz
hans@phobia.com