Rationale
The Orbeon Forms XForms engine requires keeping processing state while operating on an XForms page.
Such state includes the current values of XForms instances, selected repeated elements, and more.
With Orbeon Forms, by default XForms state information is stored on the server.
Configuring state handling
XForms document and static state caches
A property controls whether the XForms
engine should try to optimize state reconstruction by using a cache. This property should usually
be set to true:
<property as="xs:boolean" name="oxf.xforms.cache.document" value="true"/>
[SINCE: 2010-05-26] The global configuration can be overridden for each page by setting the xxforms:cache.document attribute in the page. This attribute can be set on the root element of the XHTML page, or on the first xforms:model element. Only the first such attribute encountered by the XForms engine is used:
<xforms:model xxforms:cache.document="false">
...
</xforms:model>
If oxf.xforms.cache.document is set to true, the number of XForms documents that can be
held in that document cache at a given time is configured with the following property:
<property as="xs:integer" name="oxf.xforms.cache.documents.size" value="50"/>
NOTE: This property is global and cannot be overridden on a page by page basis.
NOTE: If a user loads the same XForms page twice, two entries are created in the document cache.
[SINCE: 2010-08-16] The static state (or static analysis) of an XForms page is stored in a separate cache, controlled with this property:
<property as="xs:integer" name="oxf.xforms.cache.static-state.size" value="50"/>
This property should be set to a number equal to or greater than the number of distinct XForms pages you have.
XForms state store configuration
[SINCE: 2011-01-20 / Orbeon Forms 3.9, see historical documentation below for older versions]
NOTE: The oxf.xforms.store.application.* properties are no longer used.
When entries are evicted from the XForms document cache or the XForms static state cache, they are migrated to the XForms state store.
The XForms state store is configured via oxf:/config/ehcache.xml. The default configuration is as follows:
<cache name="xforms.state"
maxElementsInMemory="50"
memoryStoreEvictionPolicy="LFU"
overflowToDisk="true"
diskSpoolBufferSizeMB="10"
eternal="false"
timeToLiveSeconds="0"
timeToIdleSeconds="1800"
diskPersistent="false"
maxElementsOnDisk="0"
diskExpiryThreadIntervalSeconds="120"/>
This configuration sets a number of in-memory entries, and allows overflowing to disk the in-memory cache is full. Expiration of entries is set after 30 minutes of inactivity for a given entry.
Session heartbeat
If you happen to leave a browser window open on your computer, chances are that you will get
back to that window and keep using the application. The last thing you want to happen when you
come back is lose your session and therefore your data.
This is not always a correct guess of course: you may just happen to leave a window or tab open
without planning to use it again. Conversely you may have a page which is not actually visible,
for example in your browser history, yet you will come back to it. This approach wouldn’t be
good for banking applications either. Still, in many situations, such as filling-out large
forms, it sounds like a good idea to keep your session alive for open pages.
To achieve this goal you could make all server sessions longer. However this is harder to
configure for the application developer, and this won’t discriminate between pages that are
actually open on a client and the ones that are not. And while it may be ideal to have
infinitely long sessions, unfortunately many applications are not ready for this kind of
approach.
So Orbeon Forms supports a "session heartbeat" feature. Here is how this works:
-
When this feature is enabled (the default), an open XForms page in a client browser
regularly pings the server through Ajax to keep the current server session alive.
-
The ping delay is automatically computed based on the server’s session timeout. The
client pings the server at 80% of the session expiration time after the last interaction
with the server.
-
We are careful not to hit the XForms engine too much, in fact we do a very limited
amount of work on the server for each ping, so they should run fast.
-
XForms state information for pages hit with the heartbeat just migrates to the disk store over time if RAM is used by other
pages, so keeping even large numbers of pages open should not have any negative impact
on server RAM.
-
When a user gets back to using the page, state information migrates back from disk to
RAM, and the page will be live again.
-
Sessions do eventually expire as nobody keeps a browser open forever.
Note that whenever an application keeps sessions alive for a long time, it is a good idea to
keep as little data as possible in the session. The Orbeon Forms XForms engine itself uses a global state store and does not use session objects
for storage, but do remember to keep your sessions small!
The session heartbeat should help prevent many occurrences of "session expired" error messages.
As an Orbeon Forms application developer you don’t have to worry about anything: the session
heartbeat is enabled by default. You can configure it globally in properties-local.xml:
<property as="xs:boolean" name="oxf.xforms.session-heartbeat" value="true"/>
You can also override the global default by specifying a property on the first XForms model of a
page:
<xforms:model id="my-model" xxforms:session-heartbeat="false"/>
Browser navigation (back and forward) handling
When visiting an XForms page by using your browser's Back and Forward buttons, or other
browser-history mechanisms, Orbeon Forms by default restores the appearance of that page as it was
when you left it. (Browsers don't automatically handle this behavior with Ajax applications!) This
behavior best matches the usual user experience obtained when navigating regular web pages.
In certain situations, it can be useful instead to ask the XForms page to reload entirely. You
control this by using the xxforms:revisit-handling attribute on the first XForms model
of the page you want to reload. This attribute supports two values: restore (the
default) and reload. Example:
<xforms:model xxforms:revisit-handling="reload">
...
NOTE: It is recommended to use the reload value carefully, as reloading pages upon browser
navigation often does not match the expectation of the user.Historical documentation
XForms state store configuration for Orbeon Forms 2.8 until 2011-01-20 builds
When storing state on the server, the maximum size of the data to be stored globally in memory can be selected using the oxf.xforms.store.application.size property. The size is specified in bytes:
<property as="xs:integer" name="oxf.xforms.store.application.size" value="20000000"/>
When the allowed memory space for state information is full, Orbeon passivates state information to a local eXist database. Configuration parameters for the connection to the eXist database can be changed. The defaults are as follows:
<property as="xs:string" name="oxf.xforms.store.application.username" value="guest"/>
<property as="xs:string" name="oxf.xforms.store.application.password" value="guest"/>
<property as="xs:anyURI" name="oxf.xforms.store.application.uri" value="xmldb:exist:///"/>
<property as="xs:string" name="oxf.xforms.store.application.collection" value="/db/orbeon/xforms/cache/"/>
NOTE: These properties are global and cannot be overridden on a page by page basis.
client-state handling
NOTE: We do not recommend this setting, as it causes larger amounts of HTTP traffic and usually decreased performance.
State handling can be configured globally for all pages, or locally for each individual page served. Global configuration is performed in properties-local.xml with the oxf.xforms.state-handling property. When missing or set to client, state is stored client-side. When set to server, state is stored server-side. For example:
<property as="xs:string" name="oxf.xforms.state-handling" value="client"/>
The global configuration can be overridden for each page by setting the xxforms:state-handling attribute in the page. This attribute can be set on the root element of the XHTML page, or on the first xforms:model element. Only the first such attribute encountered by the XForms engine is used:
<xforms:model xxforms:state-handling="client">
...
</xforms:model>
Differences between server-side and client-side state handling
Server-side: in this case, state information is stored on the server. Only very little state information circulates between client and server. The most frequently used state information is stored in memory. Less frequently used state information is stored on disk in a local database.
Benefits of the approach:
Resulting HTML page are smaller. HTML pages increase in size as more XForms controls are used, but they don't increase in size proportionally to the size of XForms instances.
Small amounts of data circulate between the client browser and the Orbeon Forms XForms server.
This means that very large XForms instances can be processed without any impact on the amount of data that is transmitted between the client and the server.
Drawbacks of the approach:
The Orbeon Forms XForms server needs to be stateful. It uses server memory to store state information even when no request is being processed. This creates additional demand for resources on the server and slightly complicates the task of tuning the server.
State information can become unavailable when sessions expire or when the server is restarted. When state information becomes unavailable for a page, that page will no longer function unless it is reloaded.
NOTE: Orbeon Forms ensures that it is possible to open multiple client browser windows showing the same page within the same session.Client-side: in this case, static initial state information is sent along with the initial HTML page, and dynamic state is exchanged over the wire between the client browser and the Orbeon Forms XForms server when necessary.
Benefits of the approach:
The Orbeon Forms server is entirely stateless. It only requires memory while processing a client request. It can be restarted without consequence for the XForms engine.
State information does not expire as long as the user keeps the application page open in the web browser.
Drawbacks of the approach:
Resulting HTML pages are larger. In particular, the size of state data grows when XForms instances grow, regardless of whether many XForms controls are bound to instance data.
More data circulates between the client browser and the Orbeon Forms XForms server.
NOTE: Orbeon Forms compresses and encrypts XForms state information sent to the client.
By default, Orbeon forms store XForms state information on the server. Please change this default to client-side only if you have well understood the tradeoffs explained above.