You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Craig Margenau <cm...@cox.net> on 2003/08/15 21:33:37 UTC
From prepopulation, validation and reset
The prepopulation of form offered through ActionForms and the html:form tag is great, the only problem is that when the validate method returns errors, and your input page is called again, the reset() method is called thus nullifying any user inputed values. So if a user screws up 1 field on a 20 field form, when the errors are displayed it wipes out the rest of the form.
Sure there are ways around this, I use an html:hidden attribute (as someone else suggested) to pass a "noreset" param, then check that in the ActionForm's reset function. This works well but is kinda a kludge.
I also understand that you can extend ActionConfig or RequestProcessor to handle this, but again that's more complex than most would like.
The author has mentioned that adding a "reset=true/false" in the Action section of struts-config was purposely not implemented, and I can kinda understand that too, but how about a validate-error-reset="true/false" property so that you can disable the reset function only if a validation error occurs?
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: From prepopulation, validation and reset
Posted by Sgarlata Matt <sg...@bah.com>.
Hi Craig,
I've actually never used the validate() method at all. Instead, I set
up a DispatchAction with 3 methods (add, edit, save) and 2 forwards
(viewForm, and viewDetails). When the input validation fails in the
save method, the user is forwarded to the viewForm forward. When the
user inputs valid data, the user is forwarded to the viewDetails
forward. There is a lengthier description of this approach in the post
called "How to work with DispatchAction ?"
Matt
Craig Margenau wrote:
> The prepopulation of form offered through ActionForms and the html:form tag is great, the only problem is that when the validate method returns errors, and your input page is called again, the reset() method is called thus nullifying any user inputed values. So if a user screws up 1 field on a 20 field form, when the errors are displayed it wipes out the rest of the form.
>
> Sure there are ways around this, I use an html:hidden attribute (as someone else suggested) to pass a "noreset" param, then check that in the ActionForm's reset function. This works well but is kinda a kludge.
>
> I also understand that you can extend ActionConfig or RequestProcessor to handle this, but again that's more complex than most would like.
>
> The author has mentioned that adding a "reset=true/false" in the Action section of struts-config was purposely not implemented, and I can kinda understand that too, but how about a validate-error-reset="true/false" property so that you can disable the reset function only if a validation error occurs?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
--
Matthew Sgarlata
Senior Consultant
Booz Allen Hamilton Inc.
Work: 703-377-0871
Fax: 703-902-3608
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: From prepopulation, validation and reset
Posted by Jing Zhou <ji...@netspread.com>.
----- Original Message -----
From: "Craig Margenau" <cm...@cox.net>
To: <st...@jakarta.apache.org>
Sent: Friday, August 15, 2003 2:33 PM
Subject: From prepopulation, validation and reset
> The prepopulation of form offered through ActionForms and the html:form
tag is great, the only problem is that when the validate method returns
errors, and your input page is called again, the reset() method is called
thus nullifying any user inputed values. So if a user screws up 1 field on
a 20 field form, when the errors are displayed it wipes out the rest of the
form.
>
> Sure there are ways around this, I use an html:hidden attribute (as
someone else suggested) to pass a "noreset" param, then check that in the
ActionForm's reset function. This works well but is kinda a kludge.
>
> I also understand that you can extend ActionConfig or RequestProcessor to
handle this, but again that's more complex than most would like.
>
> The author has mentioned that adding a "reset=true/false" in the Action
section of struts-config was purposely not implemented, and I can kinda
understand that too, but how about a validate-error-reset="true/false"
property so that you can disable the reset function only if a validation
error occurs?
>
The order of a request processing goes like reset form bean properties,
populate form bean properties, and then validate form bean properties.
Wouldn't it be too late to disable the reset function when you find
validation
errors?
Jing
Netspread Carrier
http://www.netspread.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Form prepopulation, validation and reset
Posted by Craig M <cm...@cox.net>.
Well, let me try to explain the scenario that I am trying and maybe that
will help. This is a tasking system that I'm developing with Struts to help
me learn the framework.
I have a TaskDetailAction, a CreateTaskAction and a SaveTaskAction. I'm
trying to share an ActionForm named "TaskForm" with these 3 actions since it
encapsulates everything about a task. The TaskDetailAction prepopulates
TaskForm with values from the database when a user clicks on an existing
task; then I findForward to the jsp containg the form and it properly
prepopulates the form fields I set in TaskDetailAction. Same goes for
CreateTaskAction with the exception of the default form values I set,
forwarding to a similar jsp that also prepopulates from TaskForm.
SaveTaskAction is called from either jsp when the user clicks on a "Save"
button
So, I use "validate=true" with the SaveTaskAction, and the other 2 actions
have "validate=false" set since they are really only responsible for the
prepopulation.
My reset() method in TaskForm sets all it's attributes to null. I thought
this was necessary after consulting numerous documents/books on Struts, to
make sure you always have a clean ActionForm...this could be my mistake.
Anyhow, the problem that I see is that when validate() prior to
SaveTaskAction (and yes I want this one to use validate to take advantage of
Struts' features), and validation errors are found, it will then forward to
your input page defined in struts-config.xml for that action, and
automatically call reset(). Nothing is ever changed in validate(), it just
does your standard checks and populates action errors if any fields are
invalid.
Because of the reset method and because I set everyting to null in TaskForm
on a reset, it wipes out my values if an ActonError occurs.
So, are you advocating that nothing should really be put in the reset()
method (with the exception of checkboxes) ?
----- Original Message -----
From: "Ted Husted" <hu...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, August 15, 2003 9:12 PM
Subject: Re: From prepopulation, validation and reset
> If you forward to an input action (with validate=false set), then reset
> would be called, but the autopopulation would fire too, so the form is
> repopulated with the same values the user entered (which are still in
> the request).
>
> What would be lost is any ActionForm values you changed in validate, but
> that would be a misuse of the method.
>
> I'm not sure how the scenario you describe would occur. The
> reset/populate/validate/redisplay flow has been an essential part of
> Struts from the beginning, and the last thing it would do is nullify
> user input in the normal course.
>
> Meanwhile, it is true that most Struts application overuse reset. The
> only thing you really need to reset is a checkbox on a session-scoped
> form. In other cases, reset is usually redundant, since the
> autopopulation steps overwrites the properties anyway.
>
> -Ted.
>
> Craig Margenau wrote:
>
> > The prepopulation of form offered through ActionForms and the html:form
tag is great, the only problem is that when the validate method returns
errors, and your input page is called again, the reset() method is called
thus nullifying any user inputed values. So if a user screws up 1 field on
a 20 field form, when the errors are displayed it wipes out the rest of the
form.
> >
> > Sure there are ways around this, I use an html:hidden attribute (as
someone else suggested) to pass a "noreset" param, then check that in the
ActionForm's reset function. This works well but is kinda a kludge.
> >
> > I also understand that you can extend ActionConfig or RequestProcessor
to handle this, but again that's more complex than most would like.
> >
> > The author has mentioned that adding a "reset=true/false" in the Action
section of struts-config was purposely not implemented, and I can kinda
understand that too, but how about a validate-error-reset="true/false"
property so that you can disable the reset function only if a validation
error occurs?
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
> --
> Ted Husted,
> Junit in Action - <http://www.manning.com/massol/>,
> Struts in Action - <http://husted.com/struts/book.html>,
> JSP Site Design - <http://www.amazon.com/exec/obidos/ISBN=1861005512>.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: From prepopulation, validation and reset
Posted by Ted Husted <hu...@apache.org>.
If you forward to an input action (with validate=false set), then reset
would be called, but the autopopulation would fire too, so the form is
repopulated with the same values the user entered (which are still in
the request).
What would be lost is any ActionForm values you changed in validate, but
that would be a misuse of the method.
I'm not sure how the scenario you describe would occur. The
reset/populate/validate/redisplay flow has been an essential part of
Struts from the beginning, and the last thing it would do is nullify
user input in the normal course.
Meanwhile, it is true that most Struts application overuse reset. The
only thing you really need to reset is a checkbox on a session-scoped
form. In other cases, reset is usually redundant, since the
autopopulation steps overwrites the properties anyway.
-Ted.
Craig Margenau wrote:
> The prepopulation of form offered through ActionForms and the html:form tag is great, the only problem is that when the validate method returns errors, and your input page is called again, the reset() method is called thus nullifying any user inputed values. So if a user screws up 1 field on a 20 field form, when the errors are displayed it wipes out the rest of the form.
>
> Sure there are ways around this, I use an html:hidden attribute (as someone else suggested) to pass a "noreset" param, then check that in the ActionForm's reset function. This works well but is kinda a kludge.
>
> I also understand that you can extend ActionConfig or RequestProcessor to handle this, but again that's more complex than most would like.
>
> The author has mentioned that adding a "reset=true/false" in the Action section of struts-config was purposely not implemented, and I can kinda understand that too, but how about a validate-error-reset="true/false" property so that you can disable the reset function only if a validation error occurs?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
--
Ted Husted,
Junit in Action - <http://www.manning.com/massol/>,
Struts in Action - <http://husted.com/struts/book.html>,
JSP Site Design - <http://www.amazon.com/exec/obidos/ISBN=1861005512>.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: From prepopulation, validation and reset
Posted by "K.C. Baltz" <kc...@lollimail.com>.
I'd like an answer to this one too. (It's fortuitous--I just ran into
this problem today)
K.C.
Craig Margenau wrote:
>The prepopulation of form offered through ActionForms and the html:form tag is great, the only problem is that when the validate method returns errors, and your input page is called again, the reset() method is called thus nullifying any user inputed values. So if a user screws up 1 field on a 20 field form, when the errors are displayed it wipes out the rest of the form.
>
>Sure there are ways around this, I use an html:hidden attribute (as someone else suggested) to pass a "noreset" param, then check that in the ActionForm's reset function. This works well but is kinda a kludge.
>
>I also understand that you can extend ActionConfig or RequestProcessor to handle this, but again that's more complex than most would like.
>
>The author has mentioned that adding a "reset=true/false" in the Action section of struts-config was purposely not implemented, and I can kinda understand that too, but how about a validate-error-reset="true/false" property so that you can disable the reset function only if a validation error occurs?
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org