Re: Default attribute NSValidation override?
Re: Default attribute NSValidation override?
- Subject: Re: Default attribute NSValidation override?
- From: Chuck Hill <email@hidden>
- Date: Sun, 25 Apr 2004 11:06:56 -0700
What you are seeing is a conflict in the way that WO works and the way that
EOF is documented to work. The WOFramework calls validateTakeValueForKey
instead of takeValueForKey
Some Options:
1. Create your own EOEnityClassDescription to do what you want. This is
somewhat complex, but very powerful.
2. Remove the not-null restriction from the EOModel and handle this in code.
3. Look at the Validity framework in Project Wonder.
4. Catch the exception on the page and forward the value to your EO to
return the correct exception message.
HTH
Chuck
At 04:10 PM 24/04/2004 -0400, Kieran Kelleher wrote:
>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.
>
>
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
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.