Re: takeValuesFromRequest question
Re: takeValuesFromRequest question
- Subject: Re: takeValuesFromRequest question
- From: Arturo Perez <email@hidden>
- Date: Tue, 20 Sep 2005 09:49:37 -0400
Miguel Arroz wrote:
Hi!
First, sorry about posting so many basic question on this list... i'm
really enjoying learning WO, and I want to know some details about the
framework! :)
I'm trying to define a component (called ErrorLabel) that might (or
not) display an error. The ideia is to put an instance of ErrorLabel
next to a TextField, button, etc, so that when the value the user
introduces is wrong, and error label appears next to that element.
I've learned that a component gets the values from the interface and
sets them on the model object during the execution of
takeValuesFromRequest. My ideia was to build validators on the model
class, and catch the exceptions on the component.
The problem is that the takeValuesFromRequest is catching all the
exceptions, and printing error messages on the console, like
"[2005-09-20 13:41:29 WEST] <WorkerThread3> Validation failed on an
object [null] with keypath = publicTicket.email and exception: The
email property of Ticket is not allowed to be null."
How can I catch this exceptions, so that I may turn on the visibility
of the error labels? Of course, I may redefine takeValuesFromRequest so
that I grab all the values manually, and surround the code with a
try/catch, but that looks lot a lot of pointless work, and lack of
abstraction (if I need to add or remove a component, I will have to
change that code manually). Following the "If you are writing code, you
are doing something wrong" WebObjects non-official slogan, is there a
better way to do this?
Yours
Miguel Arroz
An important method for this is validationFailedWithException. I think
that's the one printing on the console. This method handles all the
exceptions thrown by the variable valueFor<KEY> methods.
So, for example, you do
public void validateEmail(...) {
if (email == good) return;
else throw new NSValidation.ValidationException("email is bad"...);
}
then validationFailedWithException captures all of that.
There's an article on StepWise that covers it:
http://www.stepwise.com/Articles/Technical/2001-06-13.01.html
_______________________________________________
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