Default attribute NSValidation override?
Default attribute NSValidation override?
- Subject: Default attribute NSValidation override?
- From: Kieran Kelleher <email@hidden>
- Date: Sat, 24 Apr 2004 16:10:56 -0400
BACKGROUND To PROBLEM
========================
I have a String attribute firstName of class EPRecipient and the field
is not allowed to be null in my EO model. I have a component where one
of the WOTextFields is bound to recipient.firstName.
In my EPRecipient class, I validate as follows:
public String validateFirstName(Object aValue) throws
NSValidation.ValidationException {
String errorMessage = "First name is required.";
// Check that it is not null
if (aValue == null) {
throw new NSValidation.ValidationException(errorMessage);
} else if (aValue instanceof String) {
// Check that it is a String with lengthgreater than zero
if (((String)aValue).length() < 1) {
throw new NSValidation.ValidationException(errorMessage);
}
} else {
throw new NSValidation.ValidationException(errorMessage);
}
return (String)aValue;
}
In my component, I handle the exceptions like this (based on pattern at
http://www.stepwise.com/Articles/Technical/2001-06-13.01.html as
follows:
public void validationFailedWithException(java.lang.Throwable
exception,
java.lang.Object value,
java.lang.String keyPath)
{
// create a fieldname by replacing the dot separators in the
keyPath
String fieldName = keyPath.replaceAll("[.]","");
// set the WOConditional boolean that displays the error string
// beside the WOTextField that failed validation
validationDictionary.setObjectForKey(Boolean.TRUE,
fieldName +
"ValidationFailed");
// set the validation error string to be displayed inside the
WoConditional
// beside the WOTextField that failed validation
validationDictionary.setObjectForKey(exception.getMessage(),
fieldName +
"ValidationString");
// set the boolean that will cause the submitAction method to return
the current
// page since it has errors to be corrected
hasValidationErrors = true;
}
PROBLEM
========
EOF is performing a default validation before it calls my
validateFirstName method and EOF throws the exception
"The firstName property of EPRecipient is not allowed to be null."
which my validationFailedWithException handles and my component then
displays this "ugly" error message.
What I expected (after reading pages 41-43 of Enterprise Objects book)
was that my validateFirstName would over-ride any default validation
and that it would catch the null and provide the exception instead of
EOF automatically doing it. How can I elegantly stop the default
validation elegantly besides resorting to special if { ... } coding for
each field in my exception handler or setting EOModel to allow null on
the field??
-Kieran
________________________________________________________________
Config = OS X 10.3.3 / Java 1.4.1 / WO 5.2.2 / MySQL 4.0.18 /
Connector-J 3.0.11
Blog: http://webobjects.webhop.org/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.