YOUR FEEDBACK
Chris Keene's Prescription for Curing the Java Flu
Pedro wrote: "Adobe and Microsoft are doing a far better job making their ...
SOA World Conference
Virtualization Conference
$200 Savings Expire May 16, 2008... – Register Today!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TODAY'S TOP SOA & WEBSERVICES LINKS


Perfect Partner for Web Services: Getting to Know XForms
Find out about XForms and why they are the perfect partner for Web Services

Digg This!

Page 1 of 2   next page »

HTML forms are one of the best-known techniques for gathering data from a user and submitting that data to a server. However, HTML forms are only simple tools and don't natively support some of the features needed by current Web applications such as sophisticated data validation. Also, the user interface created by HTML forms is essentially hard coded for one device, meaning the same form can't be easily re-tasked for, say, PDAs or mobile phones.

The W3C XForms Recommendation is one way of addressing some of these issues. (XForms is both plural and singular, so there's no XForm, only XForms.) XForms are XML tags embedded in host documents such as XHTML that, when rendered by an XForms-aware browser, give applications some rich and dynamic capabilities such as:

  • XForms can take advantage of the strong data typing offered by XML Schemas to validate user input at the client without using any scripting. More sophisticated data validation is also possible, such as enforcing relationships between different form values.
  • XForms' user interface components are device-independent, meaning they are rendered according to whatever device they are being displayed on.
  • XForms create and consume XML, rather than name/value pairs, making them the ideal client for Web services.
To show how some of these capabilities can be used, this article walks through the development of a simple XForms application that uses an Amazon Web service to query and display a typical book search.

Setting Up for XForms
To take advantage of the power of XForms, we first of all need something over and above the simple HTML forms processing model - an XForms engine. XForms engines are programs that are usually installed on the client side, for example as browser plug-ins, and typically work in the following way:

  • A request is made for a host document containing XForms markup by, for example, opening a document on a file system or issuing an HTTP GET.
  • The XForms engine reads the markup and renders the form. Because XForms' user interface components are defined in an abstract way, the same XForms will be rendered in a way that is appropriate to the client device. Therefore, while a date input field might be rendered as a calendar picker on a desktop browser, on a more constrained device such as a PDA, the same input field may be rendered as a single-line text box.
  • Once the form has been rendered, the users work with it to accomplish what they need to. As they are doing this, events will be fired to, amongst other things, enforce data validation rules, conditionally display different user interface components, or perform calculations. (XForms calculations and field updates are performed using the same depth-first search and topological sorting as spreadsheets.)
  • When the user has completed the form, he or she clicks a button to submit it. The XForms engine will then create an XML instance document and deal with this payload according to the rules defined by the form. The target of a submission is always a URI, which may mean that the XML payload is written to a file, sent to an e-mail address, submitted to a Web service, or to any other HTTP or HTTPS endpoint.
The advantage of having the XForms engine on the client is that all processing happens in one place and unnecessary traffic with the server is avoided. However, until XForms implementations become more common, developers can't always assume that their clients will have the right installation. Alternatively, server-side XForms engines can deliver equivalent XForms functionality to plain clients, usually through a combination of scripting and the normal markup of the host language. This means that clients don't need their own XForms engine, but the markup delivered to the client may be bulky and may not support the full range of XForms features.

For the examples used in this article, I'll be using a client-side XForms engine called FormsPlayer (www.formsplayer.com/content/index.html). Sidebar 1 has more details about some of the XForms engines that are available today.

XForms Basics
XForms are not intended to be stand-alone XML documents, but rather are embedded in what is known as a host "language." Often, this host language will be XHTML, but it might also be Wireless Markup Language (WML) or Scalable Vector Graphics (SVG), among others. Within their host languages, XForms closely follow the Model View Controller (MVC) pattern, which means there is a clean separation of data, presentation, and logic.

The XForms equivalent of the MVC model is, appropriately enough, the model element. An XForms model is really a template for the XML payload that will eventually be created, and it has a dual role in loading the model with any initial data. Listing 1, a basic Hello World XForms, shows a simple model inside the head of an XHTML document. Models are typically placed in the head to emphasize the fact that they are a non-rendered component. Any well-formed XML document can be placed within the model's instance sub-element, or it can contain a pointer to an external instance document Figure 1).

One of the key advantages XForms have over HTML forms is the ability to perform data validation, constraint checking, and calculations without the need for client-side scripting. XForms allows this to be done in a number of ways.

  • An XML Schema can be associated with the instance data elements. For small models, these constraints and validations can also be specified inline rather than referring to a separate XML Schema.
  • The bind element can be used to establish a data binding between user interface controls and elements in the instance document and at the same time specify a data type for the instance element. The bind element also contains any calculations or restrictions (as XPath expressions) that need to be applied.
The last part of the XForms model is the submission element, which uses a URI to describe what should be done with the XML payload once it has been populated. In our Hello World example, the XML payload is simply written out to a named file when the user clicks on the Write to Disk button.

Once the model is defined, all or part of it is exposed through user interface components. Following the MVC pattern, XForms user interface components provide a view onto the model, with the two being linked by either XPath expressions as in Listing 1, or through a bind element. Whereas HTML defines explicit user interface components such as radio buttons and check boxes, XForms defines a set of abstract components. These abstract components say what a component should do, but the actual rendering will depend on the host language and the device on which the components will be displayed.

While the XForms engine takes care of most of the rendering of the XForms user interface, developers can still have a style influence in a couple of ways. XForms can be directly styled according to the features available in the host language, so when using XHTML, this might mean using tables, headings, and other XHTML tags, with the XForms components arranged within these. However, by hard coding the styling details in this way, the device-independence of the form is limited.

The alternative styling approach is to use only the minimum host-language structure necessary to accommodate the XForms markup. Again, when using XHTML, this would mean placing the XForms model in the head section and the abstract user interface definition and bindings in the body section. An external stylesheet, such as Listing 2, would then provide the colors, fonts, and other formatting for each particular device.

The final part of the MVC pattern, the controller, equates to XForms events and actions. Events in XForms are defined by the XML Events specification, which in turn provides an element-based interface to the Document Object Model (DOM) Level 2 event syntax (see the Resources for more details). Meanwhile, XForms actions are the handlers that respond to XForms events. This means that XForms follow the well-known Gang of Four Observer pattern in which observers are attached to particular elements, which are notified when nominated events occurs, and then certain actions are performed.


Page 1 of 2   next page »

About Craig Caulfield
Craig Caulfield is a senior software engineer for a defense and commercial software house in Perth, Western Australia. He has a Bachelors degree in Computer Science, a Masters degree in Software Engineering, and holds certifications in Java, XML, DB2, UML, MySQL, and WebSphere.

SYS-CON Italy News Desk wrote: HTML forms are one of the best-known techniques for gathering data from a user and submitting that data to a server. However, HTML forms are only simple tools and don't natively support some of the features needed by current Web applications such as sophisticated data validation. Also, the user interface created by HTML forms is essentially hard coded for one device, meaning the same form can't be easily re-tasked for, say, PDAs or mobile phones.
read & respond »
SYS-CON India News Desk wrote: HTML forms are one of the best-known techniques for gathering data from a user and submitting that data to a server. However, HTML forms are only simple tools and don't natively support some of the features needed by current Web applications such as sophisticated data validation. Also, the user interface created by HTML forms is essentially hard coded for one device, meaning the same form can't be easily re-tasked for, say, PDAs or mobile phones.
read & respond »
XML JOURNAL LATEST STORIES . . .
EDI to XML: A Practical Approach
While EDI transactions account for most worldwide commercial activity, XML-based alternatives are beginning to gain traction. According to Forrester Research, stateful XML, stateless XML, and even flat file exchanges are all projected to grow at a faster rate than EDI over the next few
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
Red Hat is a trusted open source provider. Red Hat offers enterprise customers a long-term plan for building infrastructures on the quality and innovation of open source. Combining open source operating system platform, Red Hat Enterprise Linux, together with applications, management
JustSystems Contributes Key XBRL Rendering Technology to Financial Community
JustSystems announced that it is contributing intellectual property rights for its invention of eXtensible Business Reporting Language (XBRL) rendering technologies to XBRL International, the standards body responsible for the oversight of the XBRL specification. The invention, known a
JustSystems Launches Campaign for XBRL Success
JustSystems announced its campaign to help organizations adopt XBRL (eXtensible Business Reporting Language), the XML-based standard for communicating financial and business information. In related news, JustSystems also announced that it has contributed intellectual property rights of
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS


ADS BY GOOGLE
BREAKING XML NEWS
SAP Accelerates the Path to SOA for Customers
has led to customer requests for training and education involving SAP's proven design and de