At 11:54 AM -0700 2002/10/23, Wendy Smoak wrote:
Joe wrote:
 There's
 no strict reason why you need to validate action forms with the
 validate() method; it's just a convenience.
Can you say more about this?  I'm finding that I _can't_ use the validate()
method, because I need to allow my users to leave the main form and go off
to resolution, then come back to the main form.  It's only when they click
the "finish" button that I want to do the validation.
Well, here's what Struts does, more or less...

Gets the user request
Looks up an ActionMapping for it
If the ActionMapping has an ActionForm specified, it instantiates (or retrieves from session scope) the ActionForm and populates it based on the request.
If the ActionMapping specifies validate, Struts calls the ActionForm's validate method.
If validate returns a non-zero-length ActionErrors object, Struts forwards control to the ActionMapping's specified "input" path rather than forwarding control to the action class associated with the mapping.

So, given all of that, you could do the same stuff at other points in the process. My apps tend not to have really complicated forms, and besides, I've taken to using DynaActionForms, which means I don't even have to write a form bean unless I want to put in a validate method. Since I'm already writing an action, I just do that in my action instead of subclassing DynaActionForm. It's just a matter of style.

So, early in my action, I call some method which looks at the ActionForm which is passed in to execute(), validates it, and if necessary, creates an ActionErrors object. In my action, I see if that ActionErrors object has 1 or more messages, and if so, I call "mapping.findForward(...)" passing the name of a forward which I know is suitable for re-presenting the input form to the user.

Does that make sense? Basically, there's more than one way to do most everything in Struts, which is part of why so many people find it useful...

Joe

--
--
* Joe Germuska { [EMAIL PROTECTED] }
"It's pitiful, sometimes, if they've got it bad. Their eyes get glazed, they go white, their hands tremble.... As I watch them I often feel that a dope peddler is a gentleman compared with the man who sells records."
--Sam Goody, 1956

--
To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>



Reply via email to