On 20 May 2017, at 2:22 am, Chuck Hill <
email@hidden> 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?)
--