Introduction To XForms
Allan Beaufour
Presentation Overview
- The Rationale for XForms
- The XForms Language
- XForms Implementation Status
- XForms Samples
Part 1
Part 1
—
The Rationale for XForms
Definition of XForms
XForms is an XML application that represents the next
generation of forms for the Web.
— XForms 1.0 Specification
Why a New Forms Standard?
- Can hardly use any web-site without using forms:
- Search
- Logins
- Surveys
- Shopping
- Banking
- In short: HTML forms is a huge success!
Problems in Current Forms
- Presentation oriented, mixing data and presentation
- No type support
- Scripting, scripting, scripting
- Problems with non-English characters
- Accessibility problems
- Hard to make device-independent
- Hard to manage, hard to see what is returned
- No support for wizards and shopping carts etc.
Goals of XForms
- Correct current HTML Forms problems
- Extend capabilities of forms
- Use existing (XML) standards
- Make a generic forms "mechanism"
- Standardize
XForms Benefits
- Seperation of Values and UI
- Data can be checked by browser
- Declarative properties and relationships (instead of
scripting)
- XML in, XML out
- Device Independent
- Language Independent
- An open (W3C) standard
- Not only forms
Part 2
Part 2
—
The XForms Language
Hello Google (XHTML)
<head>
<title>Google Search</title>
</head>
<body>
<form action="http://google.dk/search"
method="get">
<label for="i">Google:<label>
<input id="i" name="q"/>
<input type="submit" value="Search"/>
</form>
</body>
ex.
Hello Google (XForms)
<head>
<title>Google Search</title>
<xf:model>
<xf:submission action="http://google.dk/search"
method="get" id="s"/>
</xf:model>
</head>
<body>
<xf:input ref="q">
<xf:label>Google:</xf:label>
</xf:input>
<xf:submit submission="s">
<xf:label>Search</xf:label>
</xf:submit>
</body>
ex.
Seperation of Values and UI
- XForms are split into three parts:
- The instance data
- The model
- The controls / user interface
Seperation of Values and UI
User Interface
- Separated from the (instance) data
- Has all the usual HTML Forms controls
- Defined behavior
- Possibility for type-specific controls
- New controls:
- <output>
- <switch> and <case>
- <repeat>
- <range> (slider control)
XPath – Short Intro
- Method for choosing elements in an XML document
- Can choose one element, or a set of elements
- Looks like standard directory paths
- Functions for f.x:
- type choosing
- summation
- type conversion
- simple arithmetics
- Every step can take a predicate
XPath – Examples
<x>
<y a="a">
<z>_</z> (1)
</y>
<y a="b">_</y> (2)
<y a="c">_</y> (3)
<y a="b">_</y> (4)
</x>
/x/y/z
: 1
/x[1]/y[1]/z
: 1
/x/y[@a = 'b']
: 2 4
UI Example
<instance>
<x>
<y a="test1">value 1</y>
<y a="test2">value 2</y>
<y a="test3">value 3</y>
</x>
</instance>
XForms examples:
<output ref="/x/y"/> --> value 1
<output ref="/x/y[2]"/> --> value 2
<output ref="/x/y[@a = 'test3']"/> --> value 3
In XForms, UI controls (except for
<repeat>
) is bound to the first element in a set
ex.
The Model
- Close to the MVC model concept (model, view, controller)
- The model has one or more instance documents
- The XForms model defines
- instance data state
- calculated values
- submission settings
- Can create/define dependencies between data
- Bound to data, not controls
Model Item Properties (MIP)
<bind nodeset="[XPath]" MIP="[XPath]"/>
- readonly
- Can data only be read?
- required
- Is data needed for submission?
- relevant
- Is data relevant? (like enabled/disabled)
- constraint
- When is data valid?
- calculate
- XPath expression determines data contents _
ex.1,
ex.2
Submit Parameters (excerpt)
- action
- URI for where data will be sent (http://, file://, etc.)
- method
- How will data be sent: XML, HTTP GET, HTTP POST
- ref
- XPath expressions determining which elements to send
- replace
- What happens with the returned data?
- instance
- Save returned data in an instance
Submission Benefits
- Multiple ways to submit per form
- Choose subset of instance data to submit
- Submit does not necessarily mean "go to new page"
- Can update form with returned data
XML Schema
- XForms supports and uses XML Schema
- XML Schema are facilities for describing the structure and
constraining the contents of XML 1.0 documents
- Contains definition of standard datatypes
- User can construct own datatypes
- Can precisely describe the needed elements in a document
XML Schema Types
- Simple types
- Elements that only have text
- Datatypes like: dates, numbers, time values, etc.
- Complex types
- Elements
- Attributes
- Sequences, amounts, etc.
XML Schema in XForms
- Schema information from:
<bind type="xsd:...">
<model schema="schema.xsd">
- schema information in instance data
- Simple types are evaluated immediately
- Full schema validation on submission
ex.
XForms 1.0 Second Edition
- XForms 1.0: October 14th 2003
- XForms 1.0 Second Edition: March 14th 2006
- Second edition contains a lot of bug fixes and corrections found
during practial implementation and form creation
- A better and more usable specification
Part 3
Part 3
—
XForms Implementation Status
Some XForms Implementations
Firefox XForms Extension
- Goal is full implementation of XForms v1.0 SE
- Official Mozilla project – open source
- IBM and Novell started the project. Now IBM, Mozilla, XYZ :),
and volunteers
- An extension, not a plugin
- is a fully integrated part of Firefox
- full DOM supported
- can work with all languages: XHTML, SVG, XUL, XBL, etc.
- Single-click install (~ 200 KB)
Firefox XForms Extension Status
- Works with standard Firefox 1.5.x
- Passes most of the W3C Test Suite
- Only missing few "big issues"
- Released preview v0.5 April 18th
- v0.6 any day now
- Still lots of bugs...
- Ready-to-use extension: Q3 2006
Part 4
Part 4
—
XForms Samples
AJAX – Without The Scripting
- AJAX feel and functionality
- BUT: No scripting!
Hotel Booking Summary
- 260 lines of code (with comments and spacing)
- No javascript
- Browser validation of input
- Datepickers
- "AJAX"-like fetching of price and user information
– and fetched through WS (XML)
- Easy updatable hotel and country list
- UI totally detached from data
Part 5
Conclusion
Conclusion
- More flexible and advanced forms standard
- Separates presentation, data, and logic
- Easier (complex) form creation and maintenance
- Avoids the script-nightmare
- Easier multi-modal and multi-lingual
- XML, XML, XML – better tied to current web services
- Open standard from W3C
- XForms products are just about ready now