XTech 2005: XML, the Web and beyond.

Are Server-Side XForms Engines the Future of XForms?

Discuss this paper on the XTech wiki
View XML source for this paper

Keywords

Abstract

XForms, the next generation web forms specification from the W3C, promises to make the life of web developers easier by replacing HTML forms. But while some web browser plugins are available, and while the Mozilla project has announced a project to implement XForms, Microsoft Internet Explorer appears to shun the specification. In such conditions, is there hope for XForms to ever take off outside the intranet?

In this paper, we present the result of two years of experience implementing a server-side XForms engine now part of the open source Orbeon PresentationServer. The benefit of such an approach is that it brings XForms transparently to currently deployed web browsers, including Internet Explorer, without requiring the use of plugins or other upgrades.

We consider the parts of the XForms specification that can be easily implemented server-side, and the challenges posed by implementing the remainder of the specification. We also look at how server-side XForms impacts the relationship between XForms and XHTML and between client and server.

Quick Introduction to XForms

XForms is the next generation web forms specification from the W3C. It is a recommendation since October 2003. It aims at replacing HTML forms, as well as providing other host languages such as SVG the ability to handle forms. There is no restriction on what host language XForms is used with, but it is expected to be mostly used in conjunction with XHTML.

XForms provides many benefits over HTML forms, including:

Compared to most other forms technologies, XForms provides the following benefits:

XForms was intended as a client-side technology. This means that an XForms engine, like a Cascaded Style Sheets (CSS) engine, for example, was designed to be implemented within a web browser. This was the idea of the specification all along, but if proof is needed, consider for example that the specification has provisions for submitting an XForms instance to a server.

The Problem

After Netscape succumbed to Internet Explorer in the late 90s, the development of client-side web browser technologies has largely stalled. With a market share of over 90% of the installed web browsers base, Microsoft has not seen any point in making any improvement at all and after IE 5, Internet Explorer hasn't had any serious upgrade. Following this trend, Microsoft has said it wouldn't support XForms. In fact, Microsoft has its own competing proprietary technology to push forward: InfoPath.

On the bright side, the Mozilla project has produced an ever more solid browser, culminating with the recent release of Firefox 1.0, and has announced that it was working on an XForms 1.0 implementation. There are also commercial third-party plugins available for Internet Explorer that provide XForms support.

XForms plugins and XForms support in Firefox and possibly other browsers will allow XForms deployment for applications in controlled environments such as corporate intranet applications. However the perspectives for mass-deployment of XForms outside the intranet appear very dim:

So is XForms dead as the next generation of web forms?

You Said Server-Side?

If XForms on the client cannot be a reality tomorrow, is there a way around it? Can XForms be more than a toy for technology enthusiasts? We believe that the answer is yes.

One of the benefits of XForms is that it provides a high level of functionality to the web application developer. What matters most is what the developers or its programming tools sees, not what the web browser sees. Following this logic, the solution consists in building a server-side emulation layer for XForms. This is what is meant by "server-side XForms".

In such an architecture, the developer writes XHTML and XForms code, as he would with an XForms-aware web browser. A server-side piece of software, the server-side XForms engine, translates this into languages understood by the web browser, namely (X)HTML, CSS, and JavaScript. The following figures illustrate the overall architecture of a server-side XForms implementation:

Server-Side XForms Architecture

The benefits of server-side XForms are clear:

A Simple Example

Let's consider an example that illustrates how XForms emulation can be achieved. Let's assume an XForms instance as follows:

<credit-card>
    <type/>
    <number/>
    <expiration-month/>
    <expiration-year/>
    <verification-code/>
    <valid/>
</credit-card>

This form may have associated controls looking as follows:

Examples of Credit Card Selection Form

An XForms input control, which is meant to display a text field that captures information into the number element, is embedded within XHTML:

<xforms:input ref="/credit-card/number"/>

A simple approach consists in mapping the XForms control to an HTML form element, for example as follows:

<input name="%2fcredit-card%2fnumber">

When the HTML form is submitted back to the server, the server-side XForms engine receives a parameter name (%2fcredit-card%2fnumber) and a value (the value entered by the user in the text field). The XForms engine can then decode the parameter name to /credit-card/number, associated it with an XForms instance XML document, and store the associated value into the XForms instance.

In reality, the strategy is a little more complex, because features of XML such as attributes and namespaces must be taken into account. The gist of it however is that there must be a mapping between the name of an HTML form control and a certain element or attribute of and XForms instance. How cleverly this mapping can be done is left as an exercise for the reader.

Techniques

There are several techniques useful to emulate an XForms engine server-side:

We explore these techniques in the following sections.

Markup Rewriting

This technique is mostly useful to render XForms controls As the simple example above illustrates, converting XForms controls to HTML controls is fairly simple. The technique mainly consists in converting XHTML and XForms into (X)HTML and possibly scripting. Most XForms controls have already an equivalent in HTML. There are exceptions, for example:

Such controls can however be emulated in HTML:

Examples of Controls with Open List Selection

Differences in Processing Model

HTML forms mandate a very simple processing model:

There is no level of interaction between the user and the form other than filling-out data. Additional interactivity may be provided through scripting, but that is above what simple HTML forms do in standard.

XForms on the other hand provides for much more advanced interaction. For example:

Example of XForms Repeat

Such advanced features cannot be emulated directly by HTML forms. A little more work must be performed, with the following aspects:

Consider the XForms repeat example: when a user presses an "Add" button, a new row must be displayed. Following the distinction above, some code must:

From the client's perspective, the information can be obtained in one of two ways:

Still from the client's perspective, rendering can be done in one of two ways:

Full Client-Server Round-Trips

The full client-server round-trip strategy is a simple way of achieving complex XForms behavior. Following-up on the XForms repeat example, let's assume the user clicks on the "Add" button. The following sequence of events takes place:

While the HTML form is submitted to the server, the form is not submitted to the application from the XForms programmer's point of view: the submission is intercepted by the XForms engine first.

XForms Repeat with Newly Added Row

This solution is straightforward and does not require large amount of client-side scripting, if any. It can be used in such situations as:

However, full round-trips imply latency, consume network and server resources, cause web pages to refresh, and therefore provide a suboptimal user experience.

Ajax

The latest trendy (albeit unofficially coined by Adaptive Path) acronym in the world of web applications is "Ajax": Asynchronous JavaScript + XML. While the technology is not new, it has been made popular by the use Google has recently made of it, which has started a flurry of articles and blog entries. The technology does have merits, and now has validation from a large community of developers. Most fairly modern browsers, including IE, Firefox, and Safari, are able to provide this capability.

Ajax provides benefits such as:

Now considering the XForms repeat example, this is the sequence of events that takes place:

From the end user's perspective, the page hasn't reloaded: it has just updated parts of itself.

The Ajax technique is also very useful for validation, which is a fairly complex task in XForms since it requires an XML Schema validator. With a carefully designed Ajax-based system, data entered by the user in form fields can be validated as the user types it.

Keeping State

An XForms engine works with one or more XForms models, which may each contain an XForms instance. Such an instance is simply an XML document. The life cycle of XForms processing operates on one or more XForms instances. In addition, XForms submission requires that a complete XForms instance must be submitted to a server.

This means that the server-side XForms engine must keep at least one entire XForms instance as part of the state associated with a page containing XForms controls. As with most web application frameworks, there are a few strategies to keep state, mainly:

Storing state client-side has the following advantages:

Storing state client-side has some disadvantages:

Whether state is stored client-side or server-side can be an option of the server-side XForms engine.

Supporting Client-Side and Server-Side XForms

A server-side XForms engine may also support user agents that implement XForms. This requires that the server-side XForms engine be either configurable by the developer, and/or that the XForms engine be able to detect user agents that support XForms. A server-side XForms engine can this way make transparent to the developers several types of user agents, including the following main categories:

Impact on the Client - Server Relationship

Server-side XForms splits the XForms engine into two parts: one part acts on the client, and is composed of script and state information; the second part acts on the server. Between the time an application produces XHTML + XForms, until the time the form is submitted to the application zero or more interactions may occurs between the client-side part of the XForms engine and the server-side part, whether producing full client-server round-trips, or whether using Ajax techniques. This has an impact on debugging. Documents that would be observable simply by viewing a page source within a web browser must now be observed at the server-side XForms engine level.

Relationship with Web Forms 2.0

A recent W3C submission by Opera Software introduces Web Forms 2.0, an incremental improvement over HTML forms. As mentioned in that submission, it does not compete directly with XForms 1.0. Instead, it can be a facilitator for implementing server-side XForms, by providing for example:

Whether Web Forms 2.0 will be adopted and become a de facto standard remains to be seen. At the moment, XForms 1.0 has the benefit of being an actual W3C recommendation.

Current Implementations

There are several server-side XForms implementations on the market. None covers totally the XForms 1.0 specification yet, but they are getting close. Implementations include:

The OPS implementation started with using very simple rewriting techniques, then progressively included more advanced techniques to keep state and exchange information between client and server. It aims at supporting Ajax in its next release.

Conclusion

We believe that server-side XForms is the most promising solution today to give XForms a real chance in the industry. From a technical standpoint, the technology to implement it is adequate, and implementations are getting more mature as months pass.

Acknowledgements

Thanks to Alessandro Vernet for his input.

Bibliography

[XFORMS10] XForms 1.0 W3C Recommendation.
[AJAX] Ajax: A New Approach to Web Applications.
[WEBFORMS20] Web Forms 2.0.
[OPS] Orbeon PresentationServer.
[CHIBA] Chiba.

Biography

Erik Bruchez

Software Architect, Orbeon, Inc., Orbeon, Inc. http://www.orbeon.com/

Erik has extensive experience in the software industry as an architect and consultant. He was involved with World Wide Web and Java technologies since their inception in 1992 and 1995 respectively. He has worked in all the areas of Java development, including constrained environments (J2ME), desktop applications (J2SE) and enterprise software (J2EE). A former employee of Symantec Corp. in Cupertino, he contributed to the VisualCafe for Java product line, before co-founding Orbeon, Inc., a company specialized in J2EE and XML consulting. He consulted and developed applications for companies such as WorldGate Communications (J2ME), Manugistics (supply-chain management), Sun (development tools), Volkswagen Financial Services (financial applications), and the City of San Diego (administrative applications). He is currently a specialist of web applications architecture and the architect of Orbeon PresentationServer (OPS), an open source J2EE-based platform for XML-centric web applications developed. Erik is the co-author of several articles on J2EE and web application development. Erik holds a MS/CS from the Swiss Institute of Technology (EPFL) in Lausanne, Switzerland.