Why does Orbeon Forms require a server runtime?We often get asked if, after a form is created with Orbeon Forms, it can be deployed without a server-side runtime. The answer, for the moment, is no, and here is why. In 2005, when we started implementing the XForms engine which currently ships with Orbeon Forms, Ajax had just been named as such. We thought hard about whether we should write a full client-side XForms engine in JavaScript (like more recent projects such as Ubiquity XForms and XSLTForms), or pick a hybrid approach where some code would run on the client, and some on the server. At the time, we decided that writing a full engine in pure JavaScript would be hard, and that we would be very late to the market if we went that way. The reason was that Java was simply way more productive for us than JavaScript, and we think this is still the case (we have now started using Scala on the server as well). That has proven a good choice since our XForms engine has been mature for a long time now, and that (unfortunately, in our opinion), plain JavaScript implementations are just getting there as we write. So let's see now the hybrid approach work. The hybrid approachOnce you have decided on a hybrid approach, how do you implement it? It depends how much you run on the server. In Orbeon Forms, the answer is: a lot! The server is smart, and the client is rather dumb (although that balance might progressively change in the future). So the tree of user interface controls, XForms models and instances, all that resides on the server. This means the following:
We cover these three points below. InitializationWhen you request an XForms page, Orbeon Forms:
The resulting HTML also contains links to CSS and JavaScript needed to properly display the page. Typically, requests for a given XForms page produce different HTML depending on what happens during XForms initialization. For example, the page might fetch data from a database, a list is latest news, etc.
Note that there are some exceptions to this rule. Some UI components, like trees, menus, dialogs, the rich test editor, etc. do need client-side initialization, simply because they are implemented by JavaScript libraries that do not have a server-side component at all. StateBefore a page is fully sent to the browser, Orbeon Forms makes sure that instance values and controls are kept "somewhere". This works through a mechanism of caches and stores:
This ensures that pages with which users are currently interacting remain responsive. UI updatesAs the user interacts with an XForms page through activation of buttons, tabbing through fields, etc., the client-side JavaScript runtime collects information, and after a little while sends it to the server, usually through an Ajax request (but it can also be an HTML form post in cases like file upload). The server then:
Once all that has happened, the server has two things to contemplate:
The server then compares the two states sends the differences to the client. The client updates the HTML DOM appropriately, and voilà! Now it might sound easy, but it's not quite so:
Orbeon Forms is starting to implement heuristics to minimize markup in page and Ajax response sizes, for example sending incremental updates when possible, and full HTML updates when too many changes have occurred.
|