Re: takeValuesFromForm Validation
Re: takeValuesFromForm Validation
- Subject: Re: takeValuesFromForm Validation
- From: Chuck Hill <email@hidden>
- Date: Wed, 1 Aug 2007 10:30:56 -0700
On Jul 31, 2007, at 7:18 PM, Owen McKerrow wrote:
Hi All,
I have an attribute in an entity that has a width of 1500 char. I
have over ridden the validate method for it inside the entities
java class.....
public String validateRqfJustification(String newState) throws
NSValidation.ValidationException
{
if ( newState != null ) {
if (newState.length() > 1500) {
throw new NSValidation.ValidationException("The RQF
Justification can not be longer than 1500 characters");
}
}
return newState;
}
This gets called fine when I try to save it.
I am surprised, it should not if newState.length() > 1500 as the
EOEntityClassDescription would fail on that and not call this.
However if I submit the form and the text field contains more than
1500 chars, a validation error is thrown, without going into this
method because it checks it against the width inside the model.
Correct.
I catch this exception inside the component
validationFailedWithException() method, the page gets return I
display the error message ( not the nicely formatted one form
above, but the default one ). BUT the value of the form in the
feild has been reset to what it was before they click the button.
This is not what I want. I want to tell them they can't save but
the value in the field should stay the same as what they just typed.
So 2 questions :
1) When a form is submitted why doesn't it use my validation method
for that attribute ? What validation is it calling ? i.e.
validateforUpdate() ?
See NSValidation.validateTakeValueForKeyPath
Confirms that value is legal for the object's property named by
keyPath and then assigns it to the property.
If value is valid, this method then assigns a new value to the
property. The new value may be different than value if a custom
validation method performed any coercions or substitutions. Finally,
this method returns the Object actually assigned to the property. By
default, this is value If value is an invalid value for this
property, this method throws an NSValidation.ValidationException
2) How can I get the value the user typed to stay in the form,
instead of being truncated back ?
The code that Peter Vandoros sent will fix this, provided that the
classes are compatible (no formatter failures).
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
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