cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <>
Subject Re: v2 Form.js how does onValidate work?
Date Wed, 17 Mar 2004 22:31:53 GMT
Tim Larson wrote:

>On Wed, Mar 17, 2004 at 11:18:35AM -0800, Christopher Oliver wrote:
>>Tim Larson wrote:
>>>On Tue, Mar 16, 2004 at 09:16:38PM +0000, Tim Larson wrote:
>>>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"?
>>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".
>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.
userErrors is not updated here:

>  Update userErrors based on validation errors.
>  Process request parameters via javaWidget.process:
>    This may register validation errors internally.
>  Call user-defined onValidate function:
>    This may also register validation errors internally.
userErrors is updated during onValidate() above

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

The call chain is like this:


Each time validationErrorListener() is called it increments 
"userErrors". Then after onValidate() returns showForm() checks the 
value of "userErrors".


View raw message