cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Piroumian, Konstantin" <>
Subject [RT] XForms with Cocoon
Date Thu, 21 Feb 2002 13:31:59 GMT
Good <user:time-of-day/>!

I've been trying to go deeper into XForms and implement an xsl stylesheet
that transforms a page from XForms markup into HTML. The following are
random thoughts that were coming to me during it and they are accorded by
the result of my try, consisting of a sample page in XForms format, a schema
for instance data and the stylesheet used to display the page. (Just to
remind what is XForms: it's an XML mark up format for the next generation of
HTML forms. See:

1. Introduction
A page in XForms format looks like this:

The 'model' contains: instance data, schema (W3C Schema) for the instance
data, bindings (=constraints) and submit info elements. Usually, all the
parts, except 'instance' data are static, so static XML files can be used
(although, it's possible to use XSP/JSP to generate dynamic forms and

2. It is for browsers!
XForms is a client side form representation that should be processed by the
browser, so it's not a format for server side processing. But some ideas
from it can be used to implement server side processing of forms. How XForms
can be implemented in web apps, particularly in Cocoon based applications?
Two steps are required: display a page and handle submitted data using the
same form model.

3. Displaying a form in XForms format.
Usually, the process looks like this:
    (Form description + instance data) * transformer(s) = HTML

Which means: transformer(s) takes the form description and the instance data
then represent it in the target format.

Normally, web applications use JavaBeans (or value objects in terms of
EJB/J2EE) to hold the business data. So, the first task is rather simple:
serialize JavaBeans/Value objects as XML. This can be easily solved with
Castor and proposed CastorTransformer or a logicsheet.

Transformation to HTML is a more complicated thing and requires dynamic
XPath expressions support. I've been thinking of writing some JavaScript
functions that can perform validation and visualization according to
constraints, but that requires full support of XPath in JavaScript and some
tricky things during transformation to place function calls in the needed
places. To implement a simplies XSL for displaying a had to use Xalan
extensions. For real XForms processing a special logicsheet or a transformer
will be needed. In any case, this will require an intermediate markup

4. Processing submitted data.
Procesing the submitted data requires following steps: validate user input
against the Schema and constraints, map values to according JavaBeans/Value
objects, perform the action (update, add, etc.). So, to validate the input
against a Schema, request parameters should be translated to XML. For this
purpose param names must be in XPath format (as it is going to be in XForms
browsers), like this:
    customer/address/line[1]=London, UK

As it were already proposed by Ivelin Ivanov, this XML can be unmarshalled
to corresponding JavaBeans/Value objects using Castor and a special Cocoon
action. After that binding constraints should be checked. And then a
business logic action should be performed.

5. Sample
This samples can be interesting to anybody who is interested in XForms. They
demonstrate how an XForm can be displayed. Also, there is a demonstration of
how 'relevant' and 'required' constraints can be visualized.

To see how display style is changed, add/remove 'required' from bindings or
change the expression in 'relevant' attribute. Also, in singleSelect element
selectUI attribute can have values 'menu', 'listbox', 'radio', 'checkbox'.

6. Conclusion
So, to conclude all the experience, I can state that for server-side XForms
support will be needed some intermediate markup format, a pair of
transformers/logicsheets, a mapping tool (like Castor) and formatting

Any comments?

Btw, is there any activity in ExFormula?

Best regards,

Konstantin Piroumian
Software engineer

Protek Flagship LLC
Phone: + 7 095 795 0520 (add. 1288)
Fax: + 7 095 795 0525

View raw message