Hi Paul, After reading this a few times it is still not clear to me what the issue is but I’ll try to say something helpful.
“takeValuesFromRequest()” does try to do some validation if it can figure out the key paths and figure out a “validate()” method to call. Obviously if it is just a method on the page it cannot “discover” validation methods to call because it doesn’t know the underlying logic or how to get to the EO that is covered by the custom WOComponent method. This type of “automatic” validation only can happen when you are setting a value hanging from an EO listed directly in the .wod “editingContext.saveChanges()” also calls these same validation methods. “woComponent.validationFailedWithException()” is an important method to implement to catch a bunch of the exceptions during takeValuesFromRequest() so you can show them all to the user. AARON ROSENZWEIG / Chat 'n Bike <http://www.chatnbike.com/> e: aa...@chatnbike.com <mailto:aa...@chatnbike.com> t: (301) 956-2319 > On May 20, 2017, at 1:37 AM, Paul Hoadley <pa...@logicsquad.net> wrote: > > On 20 May 2017, at 9:35 am, Paul Hoadley <pa...@logicsquad.net > <mailto:pa...@logicsquad.net>> wrote: > >> On 20 May 2017, at 2:22 am, Chuck Hill <ch...@gevityinc.com >> <mailto:ch...@gevityinc.com>> wrote: >> >>> Looking at the code, it looks like it should work. >>> WOKeyValueAssociation.setValue() does the validation and calls that method. >>> Is it calling it on a different component than in the first example? >> >> It’s not calling validationFailedWithException() on any of: >> >> * MyText >> * Page >> * Session >> * Application >> >> Change it back to caret-notation, it gets called on Page. Bizarre. > > Here’s another clue. Recall that the page looks like this, in part: > > <wo:MyText value="$item.content" /> > > What I hadn’t noticed was relevant was that Item.content (the attribute with > allowsNull = N) is initially null—it comes to that page and is rendered with > nothing in that textfield. So when MyText looks like this: > > <wo:text value="$value"></wo:text> > > and I just submit the form, the value of Item.content has not changed, and so > setValue() isn’t called. Hence WOKeyValueAssociation.setValue() isn’t called, > and so on—there’s now no surprise that none of those > validationFailedWithException() methods gets hit. If I put something in > Item.content before the page is rendered, then delete it from the textfield, > submit: boom. MyText.setValue() is called, Page.validateTakeValueForKeyPath() > and then Page.validationFailedWithException(), which is just what we want. > > Why does this all matter? (Bear with me—I said it was esoteric. Chuck, you > still here?) Because it’s inconsistent. Say what I’ve _actually_ got on the > page is more like this: > > <wo:textfield value="$item.summary" /> > <wo:MyText value="$item.content" /> > > Item.summary and Item.content are both allowsNull = N. If those attributes > are both null on page load, and present with empty text fields, when I submit > the form I get only a single exception (on item.summary) via automatic > property validation. If I’m checking for those exceptions prior to calling > saveChanges(), the user can get this sub-optimal experience: > > 1. User submits blank form. > 2. Form returned with “You must enter a summary” (because > validationFailedWithException() was hit by automatic property validation). > 3. User submits form with summary. > 4. Now form returned with “You must enter content” (because saveChanges() > threw a ValidationException). > > In this trivial example, yes I could just ignore these automatic property > validation exceptions altogether and call saveChanges() and get the expected > two ValidationExceptions. But let’s just say I don’t want to do that. (Or, > let’s ask why we even have automatic property validation if we can’t rely on > it.) Clearly this isn’t a bug, as such. But is there an alternate idiom to > avoid the inconsistency? (Am I imagining the inconsistency because I’m doing > something stupid?) > > > -- > Paul Hoadley > http://logicsquad.net/ <http://logicsquad.net/> > https://www.linkedin.com/company/logic-squad/ > > > > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/webobjects-dev/aaron%40chatnbike.com > > This email sent to aa...@chatnbike.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com