Re: EOGenericRecord vs. storedValue methods
Re: EOGenericRecord vs. storedValue methods
- Subject: Re: EOGenericRecord vs. storedValue methods
- From: Chuck Hill <email@hidden>
- Date: Fri, 25 Aug 2006 14:33:23 -0700
Hi Patrick,
On Aug 25, 2006, at 2:28 PM, Patrick Robinson wrote:
I've been experiencing some confounding property validation
behavior, and I just figured out how to reproduce it. I get one
behavior if my EO class is EOGenericRecord, and a different
behavior if it's a custom class using the storedValue methods.
I've got a WOTextField bound to a Number attribute of an EO, and
I've implemented validationFailedWithException() in the usual way:
public void validationFailedWithException(Throwable e, Object
value, String keyPath) {
try {
takeValueForKeyPath(value, keyPath);
} catch (IllegalArgumentException iae) {
// ignore
}
super.validationFailedWithException(e, value, keyPath);
}
Now here's the bizarre part. If the EO's class (as set in
EOModeler) is EOGenericRecord, and I enter non-numeric data in the
form field, then when validationFailedWithException() is called (so
that keyPath is someEO.someNumber), it calls takeValueForKeyPath(),
and successfully puts the bad data back into the EO's someNumber
attribute (that is, no IllegalArgumentException is thrown), and the
user sees the bad data he entered in the form field.
Yes, because it is just storing an Object in a dictionary.
However, if I make a custom class for the entity, and generate the
class files as usual so that the accessors look like this:
public Number someNumber() {
return (Number)storedValueForKey("someNumber");
}
public void setSomeNumber(Number aValue) {
takeStoredValueForKey(aValue, "someNumber");
}
If I do that, and then enter non-numeric data in the form field
bound to someEO.someNumber, then the call to takeValueForKeyPath()
in validationFailedWithException() throws an
IllegalArgumentException, and the bad data does NOT make it back to
the form field, and the user does NOT see the bad data that he
entered.
IllegalArgumentException is from Java as your code has passed a
String to public void setSomeNumber(Number aValue).
Is this just one of the side effects of EOGenericRecord's using
dictionaries to store what are, conceptually, instance variables?
Since it's a dictionary, it can cram any kind of object you want in
there, at least while it's bouncing around the UI. Coercing data
to the right types can be put off 'til validation and saving to the
db?
Yes, exactly. You could alter the templates and generate your custom
classes as:
public Object someNumber() {
return storedValueForKey("someNumber");
}
public void setSomeNumber(Object aValue) {
takeStoredValueForKey(aValue, "someNumber");
}
then cast someNumber() when you need a real Number.
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