On Wed, Mar 17, 2004 at 11:18:35AM -0800, Christopher Oliver wrote:userErrors is not updated here:
Tim Larson wrote:
On Tue, Mar 16, 2004 at 09:16:38PM +0000, Tim Larson wrote:See ScriptableWidget.notifyValidationErrorListener(). In the body of the (user-defined) onValidate() function, any call to <Widget>.setValidationError() implicitly invokes the validationErrorListener function which, in turn, increments "userErrors".
One of the specific questions is in this code:
var wk = cocoon.sendPageAndWait(uri, this.formWidget_, fun, ttl); var formContext = new FormContext(cocoon.request, javaWidget.getLocale());
var userErrors = 0;
this.formWidget_.validationErrorListener = function(widget, error) {
if (error != null) {
userErrors++;
}
}
var finished = javaWidget.process(formContext);
if (this.onValidate) {
this.onValidate(this);
}
if (!finished || userErrors > 0) {
cocoon.continuation = this.local_.webContinuation;
this.local_.webContinuation.continuation(this.local_.webContinuation);
}
return wk;
How does the call to "this.onValidate(this);" affect whether the form is redisplayed to the user when it does not modify either of the variables "finished" or "userErrors"?
Yes, but it looks like this increment would not happen until after the next sendPageAndWait, which would be too late. Running the sample you can see that it really does happens before the jump back to the bookmark and thus before the next sendPageAndWait, but I am just missing how/why it works.
Here is the sequence I read in this code:
Send form to browser with sendPageAndWait.
Receive the POST and continue on the next line of this script.
Update userErrors based on validation errors.userErrors is updated during onValidate() above
Process request parameters via javaWidget.process:
This may register validation errors internally.
Call user-defined onValidate function:
This may also register validation errors internally.
Perhaps what seems strange to you is that the "userErrors" variable is part of the closure of the function that is set as the validationErrorListener property on the form widget. Thus calls to that function modify its value in the call frame of showForm().Conditionally jump back to bookmark: This will eventually case another sendPageAndWait, and another update of userErrors, etc.
To me it looks like userErrors is getting updated at the wrong point
in this loop, meaning that it will not know about validation errors
until after the page has already been resent to the browser. I must
be misreading/misinterpreting something to come to this conclusion,
because the sample form seems to work correctly.
The call chain is like this:
Form.showForm()->Form.onValidate()->ScriptableWidget.setValidationError()->validationErrorListener()
Each time validationErrorListener() is called it increments "userErrors". Then after onValidate() returns showForm() checks the value of "userErrors".
Chris
