• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: EOGenericRecord vs. storedValue methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOGenericRecord vs. storedValue methods


  • Subject: Re: EOGenericRecord vs. storedValue methods
  • From: Patrick Robinson <email@hidden>
  • Date: Fri, 25 Aug 2006 21:16:06 -0400

Thanks for confirming, Chuck. I guess changing the EOGenerator templates is about the only way to continue enjoying that particular behavior. Or, I suppose another approach would be to bind the form fields to strings (or something), and try to copy them into EO properties in the action method. Hey, waitaminute! Didn't you cover this in your book? <flip, flip, flip> .... ah, yes. I should've remembered. Ch 5. DictionaryHoldingAreaPage.java

:-)

Thanks again,

- Patrick


On Aug 25, 2006, at 5:33 PM, Chuck Hill wrote:

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

-- Patrick Robinson AHNR-IT, Virginia Tech email@hidden



_______________________________________________
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


References: 
 >EOGenericRecord vs. storedValue methods (From: Patrick Robinson <email@hidden>)
 >Re: EOGenericRecord vs. storedValue methods (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: WebObjects 5.4 going open source
  • Next by Date: Looks like ThinkSecret got some of the scoop on WO from WWDC'06
  • Previous by thread: Re: EOGenericRecord vs. storedValue methods
  • Next by thread: awakeFromInsertion Oddity
  • Index(es):
    • Date
    • Thread