Action Syntax
Availability
This feature is available since Orbeon Forms 2018.2.
Rationale
Orbeon Forms supports services and actions. With Orbeon Forms 2018.2, a first step towards more powerful actions is introduced. There is no interface for it yet, but instead an XML configuration which you can paste into the form definition via the "Edit Source" dialog.
Enhancements
In addition to the features available through the Simple Actions dialog, the following enhancements are available:
Call an action in response to multiple events.
Support more event types.
Call an arbitrary number of services.
Run actions without calling services.
Clear repeated grid or repeated section repetitions.
Add repeated grid or repeated section repetitions.
Repeatedly run parts of an action. [SINCE Orbeon Forms 2019.1]
Conditionally run parts of an action. [SINCE Orbeon Forms 2019.1]
Updating the form definition
You place listeners and actions within the source code, preferably before the end of the main <xf:model>
content. For example:
Examples
For concrete examples of Action Syntax use, see Action Syntax examples.
Listeners
Basic syntax
A listener looks like this:
NOTE: It is disallowed to mix and match, in a single listener, events for which a control name is required and events for which a control name is not required. Instead, use multiple listeners.
Modes supported
new
edit
view
pdf
Events supported
Controls:
enabled
: the control has become enableddisabled
: the control has become disabledvisible
: the control has become visible (for example in a wizard page)hidden
: the control has become hidden (for example in a wizard page)value-changed
: the value of an enabled control has changedactivated
: the control has been activated (clicked, or enter in text field)item-selected
: an item of an enabled control has been selecteditem-deselected
: an item of an enabled control has been deselected
Form load:
form-load-before-data
: run before the data's initial values are calculatedform-load-after-data
: run when the data is readyform-load-after-controls
: run after the controls are ready
See also Running processes upon page load for the detail of the form load events.
Actions
Basic syntax
An action looks like this:
Control structures
Iterating over data
[SINCE Orbeon Forms 2019.1]
Basic usage
<fr:data-iterate>
allows you to iterate over data. The contained actions are executed once for each value returned by the expression.
Containing actions can include one or more calls to services.
In the following example, each repetition adds a row to the grid, calls a service, passing the attachment id, and sets the attachment value on the last row.
Nesting of iterations
[SINCE Orbeon Forms 2019.2]
Calls to <fr:data-iterate>
can be nested. This allows, for example, filling nested repeated sections and/or grids with the result of a service call that returns hierarchical data.
Example:
Conditions
[SINCE Orbeon Forms 2019.1]
<fr:if>
allows you to conditionally run a block of actions.
In the following example, with the repetition performed by <fr:data-iterate>
, the call to the service that retrieves an attachment depends on whether there is a non-blank attachment id provided.
Asynchronous actions
Previously, actions were run synchronously. That is, they were blocking any other form processing until completed. It is now possible to run actions asynchronously. This means that the form processing can continue while the actions are running in the background. This is particularly useful when the actions call services.
You can enable asynchronous actions:
at the action level, using the
async="true
attributeat the form level, using the
oxf.fr.detail.actions.async.*.*
property
Example of configuration property:
It is currently not possible to mix and match synchronous and asynchronous service calls within a given action.
An asynchronous action, by default, causes a response to the client (web browser) to wait forever for its completion. This is done to enhance the backward-compatibility of asynchronous actions. This can be disabled:
at the action level, using the
response-must-await="0ms"
attribute (or0
followed by any other unit allowed as shown below)at the form level, using the
oxf.fr.detail.actions.response-must-await.*.*
property
Example of configuration property:
If response-must-await
is set to 0ms
, a response to the client doesn't wait for the completion of asynchronous actions. Instead, the response is sent immediately, and the pending action's service calls continue to wait in the background. The client polls the server at regular intervals to check for the completion of such pending services, and then resumes the processing of the actions. This is useful when an action calls long-running services, and you don't want to keep the client waiting for its completion.
Possible values for this property and attribute are:
forever
"$length$unit"
(whitespace allowed around and between tokens)$length
is a positive long integer value$unit
is as described below
Practically, units in the ms
and s
ranges are the most useful.
Examples:
response-must-await="0ms"
: don't waitresponse-must-await="200ms"
: wait up to 200 millisecondsresponse-must-await="5s"
: wait up to 5 secondsresponse-must-await="forever
"`: wait indefinitely
For example, the Form Runner Landing page runs multiple background services to load lists of published forms. The page waits a few hundreds of milliseconds for the completion of those services, and if they take longer, for example due to a slow database, the page is shown to the user, and the services continue to run in the background.
In the future, asynchronous actions will likely be enabled by default.
Resolution of form controls
Many individual actions refer to form controls. When form controls are present in a repeated section or repeated grid, there can be ambiguity as to which control is being referred to.
For this reason, an optional at
attribute can be specified. That attribute is a space-separated list of tokens, one for each repetition level.
A token can take the following values:
start
: the first repetitionend
: the last repetitiona strictly positive integer: the repetition at that specific position
all
: all controls [SINCE Orbeon Forms 2023.1]
When the at
attribute is not present, it defaults to being relative to the action source. This usually means targeting the first repetition.
The following example sets the value of the control my-repeated-value
in all repetitions of the my-repeated-value
repeated grid to 42
Assume now that the control my-repeated-value
is within a repeated grid, itself nested within two levels of repeated sections. The following example sets the value of the control my-repeated-value
in the third repetition of the last repetition of the first repetition to 42
:
Individual actions
Calling a service
<fr:service-call>
calls a service by name.
Passing a value
or:
When calling an HTTP service, you can set XML request body values using nested <fr:value>
elements.
Passing a URL parameter
When calling an HTTP service, you can pass URL parameters using nested <fr:url-param>
elements.
Passing a SQL parameter
When calling a database service, you can pass parameters using nested <fr:sql-param>
elements.
Removing all repetitions of a repeat
This action starts by identifying a single repeated grid or section with the repeat
attribute. See <fr:repeat-add-iteration>
for details. The only difference is that with this action, at
is only used to identify the ancestor repeated sections if any.
With my-repeated-grid
nested within my-repeated-section
:
Remove all repetitions of
my-repeated-section
:Remove all repetitions of the last
my-repeated-grid
:Remove all repetitions of the first
my-repeated-grid
:Remove all repetitions of the second
my-repeated-grid
:
Adding repetitions to a repeat
This action starts by identifying a single repeated grid or section with the repeat
attribute. If the repeated grid or section is at the top-level, there is only one possible match. If the repeated grid or section is nested within one or more repeated sections, then a single repetition of the ancestor repeated sections is determined using the optional at
attribute.
With my-repeated-grid
nested within my-repeated-section
:
Insert a new repetition at the end of the last
my-repeated-grid
:or:
or:
Insert a new repetition at the end of the first
my-repeated-grid
:Insert a new repetition at the start of the first
my-repeated-grid
:Insert a new repetition after repetition 2 of the third
my-repeated-grid
:Insert a new repetition at the end of
my-repeated-section
:or:
Removing repetitions from a repeat
This action starts by identifying a single repeated grid or section with the repeat
attribute. See <fr:repeat-add-iteration>
for details.
With my-repeated-grid
nested within my-repeated-section
:
Remove the last repetition of the last
my-repeated-grid
:or:
or:
Remove the last repetition of the first
my-repeated-grid
:Remove repetition 2 of the third
my-repeated-grid
:
Setting the value of a control
<fr:control-setvalue/>
sets the value of a form control.
Clearing the value of a control
[SINCE Orbeon Forms 2020.1]
<fr:control-clear/>
clears the value of a control. For attachment controls, this clears the file but also the file metadata (filename, mediatype, and size).
Example:
Setting the choices of a selection control
<fr:control-setitems/>
sets the choices (or "itemset") of a selection control such as a dropdown or radio buttons.
NOTE: Hints are only supported for checkboxes and radio buttons as of Orbeon Forms 2020.1.
Writing to a dataset
This action takes the latest service result and saves it to the dataset specified by name. Example:
Clearing a dataset
[SINCE Orbeon Forms 2022.1.2]
This action clears the content of the dataset with the given name. Specifically, it replaces it with a single anonymous root element (<_/>
). Example:
Calling a process
[SINCE Orbeon Forms 2019.1]
Navigating to a page or URL
[SINCE Orbeon Forms 2019.1]
Setting the value of an attachment control
[SINCE Orbeon Forms 2019.1]
When the response of a service is binary, this action allows setting the value of an attachment control to the content of the service response:
This supports the following controls:
<fr:attachment>
<fr:image-attachment>
The mediatype and received by the service and the actual size of the attachment are automatically set. However, the filename is not set automatically.
See also the following actions:
<fr:control-setfilename>
<fr:control-setmediatype>
<fr:control-setsize>
Setting the filename of an attachment control
[SINCE Orbeon Forms 2019.1]
This action allows setting the filename of an attachment control. Example:
This supports the following controls:
<fr:attachment>
<fr:image-attachment>
Setting the mediatype of an attachment control
[SINCE Orbeon Forms 2019.1]
This action allows setting the mediatype of an attachment control. Example:
This supports the following controls:
<fr:attachment>
<fr:image-attachment>
Note that the <fr:control-setattachment>
action automatically sets a mediatype.
Setting the size of an attachment control
This action allows setting the mediatype of an attachment control. Example:
This supports the following controls:
<fr:attachment>
<fr:image-attachment>
Note that the <fr:control-setattachment>
action automatically sets a size.
Setting the focus on a form control
[SINCE Orbeon Forms 2022.1.2]
This action allows setting the focus on a form control. Example:
Marking a form control visited or unvisited
[SINCE Orbeon Forms 2022.1.2]
This action allows setting whether a form control is visited or not. Example:
In Orbeon Forms, a form control can be visited or not. Visited controls have been visited by the user, which means that the user navigated through the form control, possibly without changing its value. One way to visit form controls is to navigate using the "Tab" key, or to click on the form control and then click outside of it. Another way is to use the default "Save" or "Send" buttons, which by default visit all the form controls before proceeding. The notion is used to determine whether to show validation errors associated with that form control. [SINCE Orbeon Forms 2023.1] Form controls can also be visited when they are calculated, visible, and their value changes.
When working with actions, some form controls can benefit from having their "visited" status reset so that the user doesn't see extra errors appear. The <fr:control-setvisited>
action allows doing that.
Alert for debugging
[SINCE Orbeon Forms 2022.1, 2021.1.2, 2020.1.7] The <fr:alert>
action is intended to be used for debugging, allowing you to get some visibility on the value of intermediary results, or more generally the value of any expression is at a given point. The value of the message
attribute uses the AVT syntax, so the example below would show a dialog with the message "The answer is 42".
Copying control content
Description
The <fr:copy-content>
action allows you to copy form content:
from non-repeated form controls to other non-repeated form controls
from non-repeated form controls to repeated form controls
from repeated form controls to other repeated form controls
See also Synchronizing repeated content.
Example
Assuming that:
control-1
,control-2
,control-3
, andcontrol-4
are all within repeated grids or repeated sectionsnon-repeated-control
is non-repeated, andcontrol-5
is repeated
Then, in the following example, each <fr:map>
expresses that all repeated controls denoted by the left
attribute (source) are copied to the corresponding repeated controls denoted by the right
attribute (destination).
Repeated source and destination
When both the source and destination are repeated, the destination repeat's iterations are enforced, which means:
Extra iterations in the destination are removed from the end if needed, to match the number of iterations in the source.
New iterations in the destination are added at the end if needed, to match the number of iterations in the source.
For each iteration, the values of controls specified with
<fr:map>
are copied over.
Each <fr:map>
element can individually refer to separate repeated grids and sections. In other words, not all left
need to be in the same repeated grid or section, and not all right
need to be in the same repeated grid or section.
Non-repeated source and destination
When the source is non-repeated and the destination is also non-repeated, the value of the control is simply copied.
Non-repeated source and repeated destination
When the source is non-repeated and the destination is repeated, the value of the control is copied to one or more of the destination controls. The right-at
attribute can be used to control this behavior:
start
: first control onlyend
: last control onlystrictly positive integer: specific position
all
: all controls
Repeated source and non-repeated destination
This scenario is not supported yet.
Warning the user
When the warn
attribute is set to true
, the action will show a warning dialog if the action will overwrite existing content in the destination. An overwrite is considered when:
The destination has more iterations than the source.
The destination has the same number of iterations as the source or less, but the action would overwrite a non-blank destination value.
The default is false
.
Error handling
With Orbeon Forms 2018.2, errors when running services are silently ignored and the action continues.
With Orbeon Forms 2019.1, errors:
cause the entire action to stop.
run the
oxf.fr.detail.process.action-service-error
process
The default implementation of the service error process is as follows:
You can provide your own service error process in properties-local.xml.
Evaluation context of XPath expressions
The context item used for XPath evaluations is set as follows:
At the beginning of an action, it is the root element of the form data.
Within an
<fr:data-iterate>
, and until a service response is available, it is the current iteration item.After a service call, whether at the top-level or within an
<fr:data-iterate>
, it is the root element of the preceding action response.
[SINCE Orbeon Forms 2019.1]
You can explicitly set the XPath evaluation context to the current iteration item within a <fr:data-iterate>
with the expression-context
attribute set to current-iteration
.
In the following example, without the expression-context="current-iteration"
attribute, the second <fr:value>
would evaluate within the context of the first service call's response.
To be more explicit, the attribute can also be set on the first <fr:value>
:
See also
Blog post: Making sense of Form Runner Actions
Last updated