Neg wrote:
> Now the strings that the validate function returns should identify which
> parameter has failed validation, perhaps in say this format...
>
> parametername/error.text.key
>
Have a look at the new ActionError and ActionErrors classes in version 1.0.
Though there's not yet an accompanying tag to display specific errors, they
do what you've described:
You have to write your "validate" method like this:
public ActionErrors validate(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
if (!validA(fieldA))
{
errors.add("fieldA", new ActionError("classX.fieldA.notValid"));
}
...
return result;
}
> When processValidate calls validate on the ActionForm, it can check to see
> if any of the failed validations are on the same page as the one that was
> just submitted. If so, redisplay the form with the errors *for just this
> page*.
>
> If there are no errors on this page, then there is a choice of 2 things
> depending on what the user requested.
>
> 1) If the user has requested 'submit the whole form', then take the user
> back to the page with errors in it.
>
> 2) If the user has request to move to a different page in the form, then
> allow them to do this and if the page they are moving to has validation
> errors, then display them.
I've not tried it, but when the "processValidate" fails, it tries to return
to the input form, setting the errors in the request. From there, you should
be able to take this kind of decision. You can find which fields have errors
and decided then on which page you want to redirect the user.
Just like the discussion on global/local validation, I don't think you can
factorize a general behavior for error processing. Suppose -- that's a crazy
example -- that you have a login form with 2 pages: one for the login name
and the other one for the password. If the validation fails, should the code
decide to present the login or the password page? Only you can take the
decision to include business rules like "the user must clear the password if
he wants to change his login name".
Pierre M�tras