cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Larson <...@keow.org>
Subject Re: v2 Form.js how does onValidate work?
Date Wed, 17 Mar 2004 20:03:14 GMT
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.
  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.
  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 continuation is  invoked by this line:
> 
>   this.local_.webContinuation.continuation(this.local_.webContinuation);

Thanks.

--Tim Larson

Mime
View raw message