Re: Validation retruns the same page
Re: Validation retruns the same page
- Subject: Re: Validation retruns the same page
- From: Sacha Mallais <email@hidden>
- Date: Fri, 27 May 2005 09:57:29 -0700
On May 27, 2005, at 7:59 AM, Florijan Stamenkovic wrote:
On May 27, 2005, at 13:56, email@hidden wrote:
Hello,
after an error happend.
After the form submitted values that failed validation (for example
not typing in a field that requires it)
the method
-------------------------------------------------------------------
public void validationFailedWithException( Throwable e, Object
value,
String keyPath )
{
}
-------------------------------------------------------------------
will execute.
My question is, how can i return the same page where the error
happend?
What I do when I am forced to use validationFailedWithException(),
is that I set a boolean invalidInput = true within it. As
validationFailedWith... is called just after submitting the form,
and since normally a method is performed just after it, I just
check my boolean to see if validationFailedWithException failed,
and return the same page then. Of course, you must reset your
boolean in awake() (i do it in sleep()) methods of the component,
otherwise it stays around forever...
This is the right idea, though I would extend it to handle more than
one error at a time. Insert error message into an array or something
along those lines, then make a method hasErrors() that just returns
errors.count() > 0;
After validationFailedWithException is called, your action method
will be called, so in any method that it matters, you should have
something along the lines of
if (hasErrors())
{
// display an error message and...
return this
}
else
{
// save the eo and...
return next page
}
I am not sure this is a good pattern to make. I ONLY use it when I
have to edit an EO. That is because if I have that EO, and it is
old, and it is by itself ok, then if on submit you fail validation
with your changes, the changes will not be applied, and you can not
validate your object in the invokeAction phase. I mean, you can,
but you will not see the changes because they will not be applied.
If it is a new EO, with no values set yet, then I ignore
validationFailedWith.. and just call validateForSave on the EO in
my action.
If you need to view/save the values, you can do so in
validationFailedWithException. You can even force them into the EO
by bypassing validation and setting the value directly.
sacha
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden