April 22, 2003

Flow script + XMLForm = killer combination

XMLForm is a solution provided by Cocoon to handle forms. It's composed of two parts : an Action, which is supposed mimic Struts, and a Transformer, which handles population of form data from the data model using an XForms-like syntax.

I always found the XMLForm action to be too heavy (requires a lot of Java coding) and poorly designed compared to other Cocoon components. The Transformer, however, does its job well, even if its code is... ehrm... messy.

Enter the flow script and the integration of XMLForm and flow written by Andrew Christopher Oliver. All I can say is that it kicks ass !!!

I needed to set up quickly a demo of an interactive editor for highly structured XML document specified by an XMLSchema. Spent a few days (and nights) working on a layout stylesheet and some client-side JavaScript, and the demo was then a breeze to set up ! Multipage wizards with lots and lots of inputs organized in groups, tables, with expandable collections, detailed validation messages, etc, etc. The customer instantly decided to go with us on this project. Cool !

What's needed now is automatic validation using an XMLSchema (I'm planning to use the partial validation features of MSV). The XMLFormTransformer also needs to handle nested repeat tags and I'm thinking about refactoring rewriting it so that it is more maintainable.

Or should I take the Woody train just started by Bruno ? At first sight, it looks yummy, but I'm wondering if defining validation rules inside form layout is good or if they should be better separated in a schema. SoC, or over-SoC ?

Update
After reading the docs, I was wrong about Woody : the "form definition file" is actually a schema (I was confused by the name and the presence of labels), and the "form template" is actually the form itself, populated with values from the (let's call it so) form schema instance.

Some questions, though :

  • my demo mentioned above (which lives on a public site - just ask me where) allows creation of new elements in a collection on the client-side. Can Woody handle that (this means a repeater can accept new items from the incoming request) ?
  • the expression language is yet-another-expression-language. Please, use one of the existing ones like XPath or Jexl ! 
  • is it really different from Torsten's Precept (schema-driven validation) ?

Mmmh... interesting discussions are coming !

Update again
Steven pointed out the confusion that I once again did between the "Oliver's" : the guy that brings so much nice stuff in Cocoon's flow engine is of course Christopher. Sorry to have once again made this mistake. "Andrew" must be engraved in my brain because of its numerous rants. Be assured that I only mix the firstnames (maybe also because their last name is also a firstname), but not the people nor the work they do.

Update again and again (sep 2003)
If you find this page now, please consider the changed that occured in the previous months: don't use XMLForm, but Woody! XMLForm is buggy, limited and has security weaknesses. Woody is very strong and featured.

Posted by Sylvain Wallez at April 22, 2003 07:00 PM
Comments

i think validation rules should be external to the form. but one should have the ability to also place rules inside the form, because sometimes for certain views you want to have tighter restrictions.

Posted by: peter royal on April 22, 2003 08:00 PM

Credit where credit's due: that integration code comes from Christophe Oliver (coliver@apache.org), and not Andy C. Oliver (acoliver@apache.org). As much as Andy's rants amuse me, his only contribution to the Cocoon code base so far has been the HSSF serializer, which he doesn't consider to be a POI issue anymore. About XMLForm vs Woody, I'm pretty sure you know which framework will be the better supported/documented one ;-)

Posted by: Steven Noels on April 22, 2003 09:30 PM

In Woody, validation rules aren't really specified in the form layout. The form definition file doesn't contain any layout information at all. In a sense, it describes the schema of the form.

As for Woody vs XMLForm, just use the best tool for the job. I'm sure you're able to support yourself either way :-)

Posted by: Bruno Dumon on April 22, 2003 10:41 PM

Bruno, as I explained in my update, I was actually confused by the naming of files ("form definition file" is a actually a schema).

As for the best tool to use, don't be afraid : I know where the community and the good work is. But this also means I will input my requirements there ;-)

Posted by: Sylvain Wallez on April 23, 2003 09:11 AM

Be sure it is different... at least in one major aspect: the abstraction of the the schema. One word - Schematron.

Ivelin and me disunited about the use of Schemtron. IMNSHO Schematron is not very well suited for form validation from the *machine* point of view. And I always wanted to automagically generate client side validation, too. This is almost impossible with Schematron because you basically only have one type of validator: the xpath expression validator. Easy to understand for humans - but not to generate javascript. But this could have been ignored.

Much worse: having the view definitions implicitly inside the Schematron schema (the phases concept) mixes concerns!

Posted by: Torsten Curdt on April 23, 2003 09:59 AM

ups ...or did you mean compared to woody?

Posted by: Torsten Curdt on April 23, 2003 10:01 AM

Yes Torsten, the comparison was with Woody ! Both are schema-based, and I really would like to see a single framework for schema-based forms (be it relax, WXS, woody, commons validator, etc).

Posted by: Sylvain Wallez on April 23, 2003 10:37 AM

First of all, Sylvain, I'd sure be interested to take a look at your demo.

For some of your points, I'd prefer to just answer something like "hmmyeahno", but I'll try to translate feelings to rational arguments :-)

* a repeater could indeed accept new items coming from the request. In fact, the current form demos work completely stateless, nothing is stored in the session.

* XPath is an XML-oriented language, and may not make sense for Woody's purposes. I say may, because I didn't put much thought to it yet, I just reused xReporter's query language. I don't know jexl, I'll take a look at it. On the other hand, the expression language is dead simple (which is also important, since form definitions should be easy enough to be created by non-programmers, and it may also help in translating them to javascript equivalents).

* Then about Precept. I think the only point where Precept and Woody resemble is that they both use a tree-like datastructure that is constructed by and validated against some kind of schema. Woody's "schema" is however strong on validation of individual fields, and doesn't really have structural validation (or in fact, the instance always conforms to the schema because the schema leaves no choices). On the other hand, the items in Woody's form instances (the widgets) can hold whatever data they like, such as Long or Date objects, while with XML it's all text.

I think the effort required to make a general XML-based, WXS/RNG-grammar based form solution, just isn't worth it, at least not for many of the common form requirements (you could of course dumb-down XML and WXS or RNG to an easy manageable subset, but please lets not call them by those names anymore then. That's just confusing). WXS/RNG are strong at describing the structure of XML documents, while for forms, the end-user doesn't care about structure, (s)he just fills in individual fields (and because of this, the end-user would often probably not be able to fix any structural validation failures -- let alone understand them).

The form designer would also need to have a fair bit of advanced XML knowledge, while the goal of Woody is to make creating forms really easy.

As a side-remark, it bothers me somewhat how WXS, RNG and even commons-validator are mentioned in one go just as if they are equivalent. Just the difference in power between WXS and RNG is enormous. For example, while I could imagine implementing a partial validator for WXS, I wouldn't know how to do this for RNG.

Posted by: Bruno Dumon on April 23, 2003 02:45 PM

test

Posted by: ron on June 18, 2003 06:36 AM