cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <>
Subject Re: CForms flowscript API musings
Date Sun, 25 Apr 2004 12:54:05 GMT
Bruno Dumon wrote:

>I'm a bit annoyed by the current status of our flowscript API's for
>CForms. I'll leave the intro for what it is and just jump right into it:
>I find that this function hides too much of how a form is processed, and
>stands in the way of doing more advanced stuff.
>I propose that instead of Form.showForm(), we just let the user control
>var form = new Form("my_form_definition.xml");
>var finished = false;
>while (!finished) {
>    cocoon.sendPageAndWait("my-pipeline", {"form": form});
>    finished = form.processSubmit();

As Chris pointed out some time ago, this way of doing things, although 
fully functionnal, creates an unnecessarily long chain of continuations. 
This can be avoided by using bookmark continuations (see the v2 JS 
stuff), but makes the code less trivial.

>In this scenario, you need to write 5 lines instead of one
>form.showForm() call. However, it provides several advantages:
>* You can pass multiple form objects to the sendPageAndWait call (the
>FTT supports referencing different forms using the location attribute on
>* allows to add custom code to be executed before the form is displayed,
>and before a form submission is processed. This last one is useful for
>multiple things:
>        - adding checks to see if the user is allowed to submit the form
>        at this moment (could be disallowed if he/she has gone
>        forward/backward in the flow and changed stuff on another form)
>        - if multiple forms were put on the page, allows to check using
>        eg a request attribute which form submission should be
>        processed.
>        - or more generally, it allows to put other links on the page
>        pointing to the same continuation but causing something else to
>        be done then processing the form submission.

Never encountered these use cases up to now, but they seem valid ones.

>* allows to use sendPage instead of sendPageAndWait for stateless

I was thinking about proposing to deprecate "showForm" in favor of 
"sendForm" and "sendFormAndWait", which are more similar to "sendPage" 
and "sendPageAndWait", along with the removal of the custom validator 
(more below).

>For convenience we could still leave the form.showForm() function, but
>make its content as simple as the one above.
>Custom validation
>The current CForms flow API's allow to specify a javascript function
>that will be called to do custom validation. However, there seems to be
>a problem with this.
>Normally, it is the (java) form.process() method that will handle the
>different stages of a form submission, which simplified is as follows:
>- widgets read values from request
>- events generated by this are processed
>- widgets are validated *if needed*
>(see also
>for the full cycle description)
>Note the "if needed" for the validation: it could be that validation
>must not be triggered, e.g. when an action widget has been activated.
>However, the additional flowscript validation function seems to be
>called always.
>Since we now have the generalized concept of WidgetValidators, I propose
>we use those to plug in the custom validation. In this way, the custom
>validation will automatically be peformed as part of the normal form
>processing cycle. WidgetValidators are currently however only part of
>the WidgetDefinitions, we could make it possible to define additional
>ones on the instances.
>The same should probably be done for event handlers. Currently the v2
>API works around this limitation by using the FormHandler to allow to
>add instance-specific event handlers.

+1. form.validator was a hack needed before the generalized validation, 
and isn't needed anymore. Also, do we still need FormHandler? My 
impression is that we can remove it completely.

>Multiple bindings
>A simple one, but often requested on the user mailing list: it should be
>possible to use multiple bindings with one form.
>Currently we have the following functions:
>To allow multiple bindings, we can extend the functions as follows:
>form.addBinding(name, bindingURI);
>form.load(name, object);
>, object);
>The current functions can be left in place use "default" as the binding
>This is a difficult issue, and touches right on the problem of how to
>integrate java and javascript logic.
>The ScriptableWidget makes that we have different "form" objects in the
>javascript and java world (with somewhat different though equivalent
>To make things more confusing, the javascript snippets that can be put
>in the binding and form definition files are supplied with the original
>Java widget objects, as is the validator function in the old (non-v2)
>There has been some discussion on pro/con ScriptableWidgets before, see:
>and follow that thread.
>The main pro/cons according to me are:
>* pro: ScriptableWidget makes it much more natural to work with the form
>in a javascript environment. Working directly with the Java objects
>feels clumsy. If you look at the v2 API, it allows to easily do some 
>powerful stuff like assigning javascript functions as event handlers.

A java interface can easily be implemented in JS: see, "implementing java 
interfaces". Sure, it's not that easy as just passing a function as a 
method argument, but we can provide convenience functions for this.

>* con: different objects, different API's, different documentation,
>needs work when new widgets or features/concepts are added. Makes it
>more difficult to do one part of logic in javascript and another part in
>Java. Makes the javascript code harder to move to Java if you want to.
>I'm still undecided on this topic (ScriptableWidget). I'd like to hear
>what others think of this, and how they are actually working today (my
>experience in using all this is rather limited). At first I was more
>towards the ScriptableWidget approach, though as I'm writing this I'm
>more leaning towards directly using the java objects, and creating some
>convenience functions to wrap javascript functions as custom validators
>and event handlers (as far as that's technically possible).

I never used the ScriptableWidget API as, being primarily a Java 
developper, the Java API is more natural to me. Also, although me may 
provide a more JS-friendly API to allow more compact notations, it 
should in no way restrict the accessibility of specific features of 
particular widget implementations. By this, I mean that the JS wrapper 
should delegate all properties and methods it doesn't know about to the 
underlying java widget.

>Actually, that's leading me to another random thought: do we need the
>javascript Form object? (this is unrelated to the ScriptableWidget
>issue) Instead we could just have some convenience functions to create a
>form instance, to get a binding object, ... Currently my code always
>contains a var form and a var formWidget, and when starting I was always
>making the mistake of using the form instead of the formWidget var, and
>now I still find it annoying.

Well, you can get the form widget using jsForm.getWidget()!


Sylvain Wallez                                  Anyware Technologies 
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }

View raw message