Re: takeValuesFromRequest question
Re: takeValuesFromRequest question
- Subject: Re: takeValuesFromRequest question
- From: Michael Warner <email@hidden>
- Date: Tue, 20 Sep 2005 10:27:29 -0700
Not sure if it is what you are after, but you can also do this
if(email != null && email.trim().length() > 0)
//accept the value (possibly for further validation, has @ etc.)
else
//return message to user..."Please supply email"
// or ignore the email field if user can leave empty.
but handling it within WO's validation methods will probably result in
more
consistent code.
M. Warner
On Sep 20, 2005, at 6:49 AM, Arturo Perez wrote:
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:
email@hidden
This email sent to email@hidden
Michael M. Warner, Ph.D.
Department of Educational Specialties/299
University of Nevada, Reno
Reno, NV 89557-0251
Phone: (775) 784-4383 x2039
Fax: (775) 784-4384
_______________________________________________
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