I'm not sure I understand you, but here goes...

When a request "hits" Struts, struts processes it with a "RequestProcessor",
the "standard" RequestProcessor does a number of things, the main steps
being:

* Either get or create the ActionForm associated with the mapping
* Populate the ActionForm from the request
* Call the ActionForm's validate method (if validate="true" in the mapping)
* Call the Action's execute method
* Forward Processing

Now as you say, the validate method of the ActionForm doesn't handle
exceptions. So my suggestion was to move your validation out of the
ActionForm's validate method and into the Action's execute method. That way
if your DAO throws an exception, you could handle it using the struts
exception handling.

>From what you say though, its not the actual validation that might throw the
exception, its when you want the DAO to pass back some info in the event of
a validation error. So how about this. Set your mapping to
validate="false" - that way the RequestProcessor will not call the
ActionForm's validate method. Then in your Action's execute method call the
ActionForm's validation method yourself.

public ActionForward execute(ActionMapping mapping,
                         ActionForm form,
                         HttpServletRequest request,
                         HttpServletResponse response) throws Exception {


   if ("Submit".equals(form.getMyParameter())) {

       ActionErrors errors = form.validate(mapping, request);
       saveErrors(request, errors);

       if (errors == null || errors.isEmpty()) {
           // do my DAO stuff here
          return mapping.getInputForward();
       }

   }

}

Niall

----- Original Message ----- 
From: "kimbuba" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 12, 2004 12:26 AM
Subject: Re: ValidatorForm exception handling


> Thnx Niall but i don't understand how to set up that.
>
> Here's my situation
> i got one action MyAction.
> and MyForm.
>
> i have a very basic validation
> MyAction if has parameter="Submit" it will do prevalidation stuff like
> loading beans to populate fileds otherwise it will let ActionForm validate
> and execute business logic.
> 1. go to MyAction and execute pre validation stuff, like access a bean
from
> DB get the ActionForm form signature execute method and set it with bean
> values.
> 2. go to myLayout don't validate and show my form with all fields
populated.
> 3.SUBMIT --> myPathSubmit --> go back to MyAction that will dispatch to
> submit logic, but before do that, go to MyForm bean and:
> 4. check validation basic stuff (like required, filed length..) and
>     4.a --> on success go to success
>     4.b --> on validation errors go back to check validation.
>     until now it is a very common validation but when my ActionForm will
> show errors i
>     would like to put on my request some other info, that came from DAO
> resources but than could throw some Exceptions.
>
> where do i have to put my own Action's execute validation dao logic plus
> basic automatic validation suffs?
>
> here's my mappings:
> <action type="MyAction"
> path="/myPath"
> input=".myLayout"
> name="MyForm"
> scope="request"
> validate="false">
> <forward name="success" path=".mySuccessLayout" />
> </action>
>
> <action type="MyAction"
> path="/myPathSubmit"
> parameter="Submit"
> input=".myLayout"
> name="MyForm"
> scope="request"
> validate="true">
> <forward name="success" path="/mySuccessLayout2.do" />
> </action>
>
> Thnx
>
> "Niall Pemberton" <[EMAIL PROTECTED]> ha scritto nel
> messaggio news:[EMAIL PROTECTED]
> > Do that kind of validation in your Action rather than ActionForm, that
way
> > you can use the struts exception handling.
> >
> > In the Action's execute method....
> >
> > if (errors from Business Delegate) {
> >   ActionErrors errors = new ActionErrors();
> >   errors.Add(....);
> >   saveErrors(request, errors);
> >   return mapping.getInputForward();
> > }
> >
> > Niall
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to