Using formsPlayer with server-side XForms processors

Since XForms can run on many different devices then it's obviously important for server-based systems such as Orbeon, Chiba and Intalio to be able to use any client-side XForms processor. This means that even if developers are aiming to avoid any installation requirement on the part of their users, it is still possible to make use of an XForms processor such as formsPlayer or the Firefox extension, if it is found to be already present on a user's machine.

To try to make this as easy as possible, we've released a GPL script that can be placed in an HTML or XHTML document, and which tries to assist in the use of client-side XForms processors if they are installed. The script will also help the user to install a processor if necessary.

The key point is to place control over whether or not to use a client-side processor in the hands of the user. When building HTML sites we try to make sure that browser choice is irrelevant, and the goal is to do the same for XForms. In this section we look at how we can do that.

The lib-xh project

To create a document that will work with many different processors we use lib-xh, an open source project hosted at Google Code :

  http://code.google.com/p/lib-xh

The source for the project is located here:

  http://lib-xh.googlecode.com/svn/trunk/

Using the library simply requires the main script to be included in source documents, as follows:

  <script src="http://lib-xh.googlecode.com/svn/trunk/xH.js" type="text/javascript">/**/</script>

Operation of lib-xH.js

At the moment the script checks for formsPlayer (if running within Internet Explorer) and for the Firefox XForms extension (if running within Firefox). If the Firefox extension is present then the script doesn't need to do anything else, but if formsPlayer is detected the correct tags need to be added to the source document so that the formsPlayer ActiveX component can be invoked. This also conveniently addresses the Eolas problem.

If neither plug-in is present then a small message is added to the top of the document along the lines of 'this form will run faster if you install x'. The message includes a link to make it easier for the user to download either the Firefox extension or formsPlayer, depending on the browser being used.

To see how this side of the script works, try running the following form in various browsers::

  http://lib-xh.googlecode.com/svn/trunk/test/basic.html

Using lib-xh to automatically install or upgrade formsPlayer

The script can also be used to automatically install formsPlayer, in situations where a project specifically requires formsPlayer to be present. It's also possible to indicate a required minimum version, which will force an upgrade if necessary. To make use of installation and upgrade features a version number is added to the document before the instruction to load lib-xH.js:

  <script type="text/javascript">
    var sLatestFpRelease = "1,5,4,1010";
  </script>
  <script src="http://lib-xh.googlecode.com/svn/trunk/xH.js" type="text/javascript">/**/</script>

An example that uses this technique is here:

  http://lib-xh.googlecode.com/svn/trunk/test/upgrade-fp.html

Note that loading this form in Firefox or Safari will give different messages to the previous example; since in this form we have specified that we must have formsPlayer installed, viewing the page in any browser other than IE will give users a message that there is no version of formsPlayer available for them, and that they should try again, using IE.

Deciding whether to deliver XForms or HTML

If you are running a server-side XForms processor then you'll also need to detect whether a client-side processor has been installed. To detect formsPlayer check the HTTP Accept headers for the string formsPlayer. If it's detected then your server can simply deliver the XForms untransformed.

[Need to check how this is done with Firefox.]

If no client-side XForms processor is detected then the transformation to HTML can continue, and the HTML delivered to the user. However, even then, if lib-xH.js is included in the output HTML, the user still has the option to install a client-side processor which would then be used for subsequent forms.

Conclusion

Since XForms can be run on a number of different processors, applications that make use of XForms would do well to empower their users to decide whether they use a client-side processor or not.