Understanding XForms


XForms is the new standard way to create forms (the specification is actually not that new, but it is definitely new to almost all developers, few of whom have ever used it). Understanding XForms a better understanding of the worlds of XML and XSL.

XML is simply a way to share structured data. XML documents are each of a specific type which defines what fields and information need to be in XML documents of that type. XForms is an XML type used to define what forms contains. That is important to understand. Unlike HTML forms which contain form controls and presentation, XForms forms contain only form controls.

Or put differently, forms contain controls (the form fields themselves) as well as presentation information (where the label should be displayed, HTML tables, and so on). An XForms form only contains controls, a list of controls and what their attributes are. Attributes include things like:

  • Field name

  • Field type

  • Field label

  • Level of nesting (if using fields within groups)

  • Type of validation required

There is no presentation at all in the XForms, just lots of information that could be used by whomever (or whatever) needs to provide the presentation.

XSL stands for Extensible Stylesheet Language, it is a language used to provide processing rules for XML. If you had an XML file containing raw movie information and you wanted to convert that data into the format your database needed, you would write an XSL file that provided the translation rules, defining how XML data is to be processed and what any generated output should look like. The XSL file is then applied, and the output you need is generated.

When working with XForms you then need to document:

  • The XForm definition of your form

  • An XSL file that defines how that form is to be rendered

The big idea is to explicitly divorce form contents from form presentation. Why is this a good thing? Consider the following scenarios:

  • You need to reorder form fields, instead of having to fight with <tr> and <td> tags you simply move the fields around, there is no presentation code to worry about.

  • You need to copy and paste parts of one form into another, without presentation code in the way it really is a simple matter of copy and paste.

  • You need a common look for all your forms, instead of having presentation code in every form you have a single XSL file that all forms use.

  • And when that look and feel needs to change, you now have a single file to change, and all forms will inherit that change automatically.

  • It makes a lot of sense. And yet very few developers use XForms. Why is that?

Barriers To XForms Adoptions

There have been three primary barriers to XForms adoption:

  • Unlike HTML forms, XForms syntax is very rigid and strict, and creating the well formed XML that XForms requires is not trivial.

  • Creating XSL is even less trivial. It is not an easy language to learn and use.

  • And worst of all, many browsers won't know what to do with XForms and XSL, and won't apply the transformation for you.

All things considered, it is easy to see why XForms adoption has been slow. And yet XForms does indeed have value, as already explained.

ColdFusion and XForms

ColdFusion can't solve all of the above problems, but it can make using XForms far easier and more manageable:

  • ColdFusion can automatically create the XForms XML, all you need to do is use <cfform> tags (the same tags you've been using in this and previous chapters), and ColdFusion will figure out what the XML you need should look like and will generate it for you.

  • ColdFusion can also apply XSL transformations on the server so that what gets sent to the browser is regular browser code. As such, browsers need know nothing about XForms and XSL because browsers never see the XForms or XSL.

  • The only problem ColdFusion can't solve for you is writing the XSL. But fortunately ColdFusion does come with some basic XSL files to get you started, and more will be made available for download.

NOTE

If you intend to use XForms extensively, you'll want to pick up a book on XSL.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net