cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <br...@outerthought.org>
Subject Re: [RT] Comparing Woody & XMLForm : towards a unified form handling (long)
Date Tue, 22 Jul 2003 20:42:56 GMT
On Tue, 2003-07-22 at 22:11, Stefano Mazzocchi wrote:
On Tuesday, Jul 22, 2003, at 11:23 America/Guayaquil, Bruno Dumon wrote:
> 
> >> Although there is a great probability that datatypes can
> >> be reused for different fields and even different forms, I'm not sure
> >> using the same fields within different templates really make sense. 
> >> For
> >> example, HTML and WML browsers have so much different screen sizes and
> >> interaction constraints that a single form definition can hardly be 
> >> used
> >> for both.
> >
> > Agreed. It is however not so much about reuse but rather separation of
> > skills: the form template will mostly be edited by a HTML designer.
> 
> Question: have you thought about using garbage as the template file?

The WoodyTemplateTransformer is somewhat different because it inserts
XML representations of the widgets, while most template transformers
look up 'primitive' (non-xml) values. But I didn't look much at the
existing template solutions yet (including garbage).

> [skip]
> >> The ongoing work on form binding considers binding as a process
> >> surrounding form population and validation : the application->form
> >> binding fills an existing form, and the form->application binding
> >> transfers form data to the application model once the form is 
> >> correctly
> >> validated.
> >
> > And in a flowscript, it's as simple as this (taken from
> > binding_example.js):
> >
> >     var document = loadDocument(documentURI);
> >     var binding = loadBinding(bindingURI);
> >     var model = form.getModel();
> >
> >     binding.loadFormFromModel(form.form, document);
> >
> >     form.show("form2-display-pipeline");
> >
> >     binding.saveFormToModel(form.form, document);
> >     saveDocument(document, makeTargetURI(documentURI));
> >     cocoon.sendPage("form2-success-pipeline");
> >     form.finish();

> I would love to see this commented a little more so that I can 
> understand more.

ok. In fact, the above code is quite rough, it's just quickly thrown
together to make it work.

But here it is:

// the form2 function is not directly called by the sitemap but by
// a generic "woody" function that instantiates the form based on
// parameters passed from the sitemap (see woody.js file)
function form2(form, documentURI, bindingURI) {
    // document contains the document to be edited as a DOM tree
    // (loadDocument is an utility function that looks up the
    //  Avalon DOMParser component to parse the file)
    var document = loadDocument(documentURI);

    // binding contains an object that can bind data between
    // a DOM-tree and Woody form (bidirectional). The binding
    // is described in an XML file and is based on JXPath
    // (loadBinding is an utility function that looks up an
    //  Avalon component which builds this binding)
    var binding = loadBinding(bindingURI);

    // we start by binding the document data to the form
    // the 'form' variable is a javascript wrapper around the
    // actual form, and 'form.form' is the actual Java form object
    binding.loadFormFromModel(form.form, document);

    // shows the form to the user until is validated successfully
    form.show("form2-display-pipeline");

    // use the binding to update the DOM-tree with the
    // data from the form
    binding.saveFormToModel(form.form, document);

    // save the DOM-tree back to an XML file, the makeTargetURI
    // function makes a modified filename so that the
    // original document is not overwritten
    saveDocument(document, makeTargetURI(documentURI));

    cocoon.sendPage("form2-success-pipeline");
    form.finish();
}

[an obvious improvement would be to make the binding also part of the
javascript-form-wrapper, so that you don't have to load the binding
yourself and can use form.load(object) and form.save(object)]

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Mime
View raw message