Re: Esoteric issue with automatic property validation and validationFailedWithException()

2017-05-21 Thread Paul Hoadley
Hi Aaron,

Thanks for jumping in.

On 21 May 2017, at 12:25 am, Aaron Rosenzweig  wrote:

> 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.

Yeah, I think ultimately it’s esoteric, as advertised, and just not very 
interesting. But thanks for trying!

> “takeValuesFromRequest()” does try to do some validation if it can figure out 
> the key paths and figure out a “validate()” method to call.

What I’m talking about here is the validation that happens just _prior_ to 
that—what Chuck calls “Automatic EOF Property Validation” on p.143 of Practical 
WebObjects. My example triggers that because there are model attributes with 
allowsNull = N.

> 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

You may well be right, despite the fact that I think we’re talking about 
slightly different phases of validation. My observation is just that changing 
this:



to this:



(even when paired with a setValue() method that calls setValueForBinding(value, 
"value”)) seems to _bypass_ the “Automatic EOF Property Validation” that 
happens in the first case above.

I’m almost boring myself talking about it now. I doubt there’s any bug, unless 
it’s in my code, I just thought someone else may have noted the inconsistency 
themselves, and could perhaps offer a workaround or something. But it’s not a 
big deal.


-- 
Paul Hoadley
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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Esoteric issue with automatic property validation and validationFailedWithException()

2017-05-20 Thread Aaron Rosenzweig
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 
e:  aa...@chatnbike.com   t:  (301) 956-2319



> On May 20, 2017, at 1:37 AM, Paul Hoadley  wrote:
> 
> On 20 May 2017, at 9:35 am, Paul Hoadley  > wrote:
> 
>> On 20 May 2017, at 2:22 am, Chuck Hill > > 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:
> 
> 
> 
> 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:
> 
> 
> 
> 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:
> 
> 
> 
> 
> 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/ 
> 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


Re: Esoteric issue with automatic property validation and validationFailedWithException()

2017-05-19 Thread Paul Hoadley
On 20 May 2017, at 9:35 am, Paul Hoadley  wrote:

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



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:



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:




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/
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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Esoteric issue with automatic property validation and validationFailedWithException()

2017-05-19 Thread Paul Hoadley
Hi Chuck,

On 20 May 2017, at 2:22 am, Chuck Hill  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.


-- 
Paul Hoadley
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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Esoteric issue with automatic property validation and validationFailedWithException()

2017-05-19 Thread Chuck Hill
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?

Chuck

From: Webobjects-dev 
<webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf of Paul 
Hoadley <pa...@logicsquad.net>
Date: Friday, May 19, 2017 at 3:52 AM
To: WebObjects-Dev <webobjects-dev@lists.apple.com>
Subject: Esoteric issue with automatic property validation and 
validationFailedWithException()

Hello,

Let’s say I have a Page component. On this page is a subcomponent, MyText, that 
looks like this in Page’s template:



And then MyText itself is just this:



Item.content is a String, and allowsNull is N in the model. So, obviously, it’s 
a candidate for automatic EOF property validation on form submission. When I 
leave the textarea blank and submit, validationFailedWithException() is called 
on the page—great.

But that’s not quite what MyText looks like—say I need to do other things with 
the bound string. So it actually looks like this:



and has a couple of accessor methods instead:

public String value() {
return stringValueForBinding("value");
}

public void setValue(String value) {
setValueForBinding(value, "value");
}

Now, when I submit a blank textarea, validationFailedWithException() is _not_ 
called on the page. What’s going on here? What have I stomped on? How do I 
trigger automatic property validation with a component like this?


--
Paul Hoadley
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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Esoteric issue with automatic property validation and validationFailedWithException()

2017-05-19 Thread Paul Hoadley
Hello,

Let’s say I have a Page component. On this page is a subcomponent, MyText, that 
looks like this in Page’s template:



And then MyText itself is just this:



Item.content is a String, and allowsNull is N in the model. So, obviously, it’s 
a candidate for automatic EOF property validation on form submission. When I 
leave the textarea blank and submit, validationFailedWithException() is called 
on the page—great.

But that’s not quite what MyText looks like—say I need to do other things with 
the bound string. So it actually looks like this:



and has a couple of accessor methods instead:

public String value() {
return stringValueForBinding("value");
}

public void setValue(String value) {
setValueForBinding(value, "value");
}

Now, when I submit a blank textarea, validationFailedWithException() is _not_ 
called on the page. What’s going on here? What have I stomped on? How do I 
trigger automatic property validation with a component like this?


-- 
Paul Hoadley
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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com