Orbeon Forms
Search…
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 "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:
1
<!-- other Form Builder code here -->
2
3
<fr:listener
4
version="2018.2"
5
.../>
6
7
<fr:action name="my-action" version="2018.2">
8
...
9
</fr:action>
10
11
<!-- Put `<fr:listener>` and `<fr:action>` just above this. -->
12
</xf:model>
Copied!

Example

The following example:
  • listens to an activation event on the button my-button
  • in response, calls the my-action action, which
    • sets values from controls into the my-service service request
    • calls the my-service service
  • when the service call completes
    • the my-table repeated grid is cleared
    • iterating over the XML response, for each iteration
      • adds a repetition at the end of the my-table repeated grid
      • sets the value of controls on the new repetition
    • finally, all the result-dropdown dropdown control items are updated
1
<!-- other Form Builder code here -->
2
3
<fr:listener
4
version="2018.2"
5
events="activated"
6
controls="my-button"
7
actions="my-action"/>
8
9
<fr:action name="my-action" version="2018.2">
10
11
<fr:service-call service="my-service">
12
<fr:value control="foo" ref="/*/foo"/>
13
<fr:value control="bar" ref="/*/bar"/>
14
</fr:service-call>
15
16
<fr:repeat-clear repeat="my-table"/>
17
18
<fr:data-iterate ref="/*/row">
19
<fr:repeat-add-iteration repeat="my-table" at="end"/>
20
<fr:control-setvalue value="@field" control="result-field" at="end"/>
21
<fr:control-setvalue value="@dropdown" control="result-dropdown" at="end"/>
22
</fr:data-iterate>
23
24
<fr:control-setitems
25
items="/*/response/item"
26
label="@label"
27
value="@value"
28
control="result-dropdown"/>
29
30
</fr:action>
31
32
<!-- Put `<fr:listener>` and `<fr:action>` just above this. -->
33
</xf:model>
Copied!

Listeners

Basic syntax

A listener looks like this:
1
<fr:listener
2
version="2018.2"
3
modes="..."
4
events="..."
5
controls="..."
6
actions="..."
7
>
Copied!
Attribute
Mandatory
Value
Comment
version
Yes
format version
always 2018.2
modes
No
space-separated list of modes
The listener is enabled for each mode listed only. If absent, the listener is enabled for all modes.
events
Yes
space-separated list of event names
When more than one event name is present, the listener reacts if any of the listed events is present.
controls
Yes for events which relate to a particular control, like enabled or value-changed
space-separated list of control names
When more than one control name is present, the listener reacts if an event is dispatched to any of the listed controls.
actions
No, but nothing will happen if there is not at least one action referenced
space-separated list of action names
When more than one action name is present, all the specified actions are called when the listener reacts to an event.
NOTE: It is not recommended 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 enabled
  • disabled: the control has become disabled
  • visible: 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 changed
  • activated: the control has been activated (clicked, or enter in text field)
  • item-selected: an item of an enabled control has been selected
  • item-deselected: an item of an enabled control has been deselected
Form load:
  • form-load-before-data: run before the data's initial values are calculated
  • form-load-after-data: run when the data is ready
  • form-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:
1
<fr:action
2
version="2018.2"
3
name="my-action"
4
>
Copied!
Attribute
Mandatory
Value
Comment
version
Yes
format version
always 2018.2
name
Yes
action name
must be unique in the form definition

Control structures

Iterating over data

[SINCE Orbeon Forms 2019.1]

Basic usage

1
<fr:data-iterate ref="...expression...">
2
...
3
</fr:data-iterate>
Copied!
<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.
Attribute
Mandatory
Value
Comment
ref
Yes
sequence XPath expression
runs in the current XPath evaluation context
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.
1
<fr:action name="populate-attachments" version="2018.2">
2
3
<fr:service-call service="get-attachments-list"/>
4
<fr:repeat-clear repeat="my-grid"/>
5
6
<fr:data-iterate ref="/*/row">
7
<fr:repeat-add-iteration repeat="my-grid" at="end"/>
8
<fr:service-call service="get-attachment">
9
<fr:url-param name="text" value="attachment-id"/>
10
</fr:service-call>
11
<fr:control-setattachment control="my-attachment" at="end"/>
12
</fr:data-iterate>
13
14
</fr:action>
Copied!

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:
1
<fr:action name="my-action" version="2018.2">
2
<fr:service-call service="get-nobel-prizes"/>
3
<fr:repeat-clear repeat="prizes"/>
4
<fr:data-iterate ref="/*/prizes/_">
5
<fr:repeat-add-iteration repeat="prizes"/>
6
<fr:control-setvalue value="year" control="year" at="end"/>
7
<fr:control-setvalue value="category" control="category" at="end"/>
8
<fr:repeat-clear repeat="laureates"/>
9
<fr:data-iterate ref="laureates/_">
10
<fr:repeat-add-iteration repeat="laureates"/>
11
<fr:control-setvalue value="firstname" control="firstname" at="end"/>
12
<fr:control-setvalue value="surname" control="surname" at="end"/>
13
<fr:control-setvalue value="motivation" control="motivation" at="end"/>
14
</fr:data-iterate>
15
</fr:data-iterate>
16
</fr:action>
Copied!

Conditions

[SINCE Orbeon Forms 2019.1]
1
<fr:if condition="...boolean expression...">
2
...
3
</fr:if>
Copied!
<fr:if> allows you to conditionally run a block of actions.
Attribute
Mandatory
Value
Comment
condition
Yes
boolean XPath expression
runs in the current XPath evaluation context
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.
1
<fr:action name="populate-attachments" version="2018.2">
2
3
<fr:service-call service="get-attachments-list"/>
4
<fr:repeat-clear repeat="my-grid"/>
5
6
<fr:data-iterate ref="/*/row">
7
<fr:repeat-add-iteration repeat="my-grid" at="end"/>
8
<fr:if condition="xxf:non-blank(attachment-id)">
9
<fr:service-call service="get-attachment">
10
<fr:url-param name="text" value="attachment-id"/>
11
</fr:service-call>
12
<fr:control-setattachment control="my-attachment" at="end"/>
13
</fr:if>
14
</fr:data-iterate>
15
16
</fr:action>
Copied!

Individual actions

Calling a service

1
<fr:service-call service="...service name...">
2
<fr:value value="..." ref="..."/>
3
</fr:service-call>
Copied!
<fr:service-call> calls a service by name.
Attribute
Mandatory
Value
Comment
service
Yes
name of the service to call
must be an existing service

Passing a value

1
<fr:value value="..." ref="..."/>
Copied!
or:
1
<fr:value control="..." ref="..."/>
Copied!
When calling an HTTP service, you can set XML request body values using nested <fr:value> elements.
Attribute
Mandatory
Value
Comment
control
No
control name
either this or value must be specified
value
No
value expression
either this or control must be specified
ref
Yes
destination expression
points to an element or attribute in the request XML

Passing a URL parameter

1
<fr:url-param name="..." value="..."/>
Copied!
When calling an HTTP service, you can pass URL parameters using nested <fr:url-param> elements.
Attribute
Mandatory
Value
Comment
control
No
control name
either this or value must be specified
value
No
value expression
either this or control must be specified
name
Yes
parameter name
URL parameter name

Passing a SQL parameter

1
<fr:sql-param index="..." value="..."/>
Copied!
When calling a database service, you can pass parameters using nested <fr:sql-param> elements.
Attribute
Mandatory
Value
Comment
control
No
control name
either this or value must be specified
value
No
value expression
either this or control must be specified
index
Yes
positive integer
SQL query parameter index

Removing all repetitions of a repeat

1
<fr:repeat-clear
2
repeat="..."
3
at="..."/>
Copied!
Attribute
Mandatory
Value
Comment
repeat
Yes
repeated grid or repeated section name
at
No
space-delimited position tokens: start, end, or a positive integer
missing leading tokens default to end
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:
    1
    <fr:repeat-clear repeat="my-repeated-section"/>
    Copied!
  • Remove all repetitions of the last my-repeated-grid:
    1
    <fr:repeat-clear repeat="my-repeated-grid" at="end"/>
    Copied!
  • Remove all repetitions of the first my-repeated-grid:
    1
    <fr:repeat-clear repeat="my-repeated-grid" at="start"/>
    Copied!
  • Remove all repetitions of the second my-repeated-grid:
    1
    <fr:repeat-clear repeat="my-repeated-grid" at="2"/>
    Copied!

Adding repetitions to a repeat

1
<fr:repeat-add-iteration
2
repeat="..."
3
at="..."/>
Copied!
Attribute
Mandatory
Value
Comment
repeat
Yes
repeated grid or repeated section name
at
No
space-delimited position tokens: start, end, or a positive integer
missing leading tokens default to end
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:
    1
    <fr:repeat-add-iteration repeat="my-repeated-grid" at="end end"/>
    Copied!
    or:
    1
    <fr:repeat-add-iteration repeat="my-repeated-grid" at="end"/>
    Copied!
    or:
    1
    <fr:repeat-add-iteration repeat="my-repeated-grid"/>
    Copied!
  • Insert a new repetition at the end of the first my-repeated-grid:
    1
    <fr:repeat-add-iteration repeat="my-repeated-grid" at="start end"/>
    Copied!
  • Insert a new repetition at the start of the first my-repeated-grid:
    1
    <fr:repeat-add-iteration repeat="my-repeated-grid" at="start start"/>
    Copied!
  • Insert a new repetition after repetition 2 of the third my-repeated-grid:
    1
    <fr:repeat-add-iteration repeat="my-repeated-grid" at="3 2"/>
    Copied!
  • Insert a new repetition at the end of my-repeated-section:
    1
    <fr:repeat-add-iteration repeat="my-repeated-section" at="end"/>
    Copied!
    or:
    1
    <fr:repeat-add-iteration repeat="my-repeated-section"/>
    Copied!

Removing repetitions from a repeat

1
<fr:repeat-remove-iteration
2
repeat="..."
3
at="..."/>
Copied!
Attribute
Mandatory
Value
Comment
repeat
Yes
repeated grid or repeated section name
at
No
space-delimited position tokens: start, end, or a positive integer
missing leading tokens default to end
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:
    1
    <fr:repeat-remove-iteration repeat="my-repeated-grid" at="end end"/>
    Copied!
    or:
    1
    <fr:repeat-remove-iteration repeat="my-repeated-grid" at="end"/>
    Copied!
    or:
    1
    <fr:repeat-remove-iteration repeat="my-repeated-grid"/>
    Copied!
  • Remove the last repetition of the first my-repeated-grid:
    1
    <fr:repeat-remove-iteration repeat="my-repeated-grid" at="start end"/>
    Copied!
  • Remove repetition 2 of the third my-repeated-grid:
    1
    <fr:repeat-remove-iteration repeat="my-repeated-grid" at="3 2"/>
    Copied!

Setting the value of a control

1
<fr:control-setvalue/>
Copied!
<fr:control-setvalue/> sets the value of a form control.
Attribute
Mandatory
Value
Comment
control
Yes
control name
value
Yes
value expression
value to set
at
No
space-delimited position tokens: start, end, or a positive integer
missing leading tokens default to end
1
<fr:control-setvalue
2
control="my-control"
3
value="current-date()"/>
Copied!

Clearing the value of a control

[SINCE Orbeon Forms 2020.1]
1
<fr:control-clear/>
Copied!
<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).
Attribute
Mandatory
Value
Comment
control
Yes
control name
at
No
space-delimited position tokens: start, end, or a positive integer
missing leading tokens default to end
Example:
1
<fr:control-clear control="my-control"/>
Copied!

Setting the choices of a selection control

1
<fr:control-setitems/>
Copied!
<fr:control-setitems/> sets the choices (or "itemset") of a selection control such as a dropdown or radio buttons.
Attribute
Mandatory
Value
Comment
control
Yes
control name
items
Yes
XPath expression returning one XPath item for each choice
label
Yes
relative XPath expression returning the label for the current choice
hint
No
relative XPath expression returning the hint for the current choice
[SINCE Orbeon Forms 2020.1]
value
Yes
relative XPath expression returning the value for the current choice
at
No
space-delimited position tokens: start, end, or a positive integer
missing leading tokens default to end
NOTE: Hints are only supported for checkboxes and radio buttons as of Orbeon Forms 2020.1.

Writing to a dataset

1
<fr:dataset-write
2
name="..."/>
Copied!
Attribute
Mandatory
Value
Comment
name
Yes
dataset name
This action takes the latest service result and saves it to the dataset specified by name. Example:
1
<fr:dataset-write
2
name="my-dataset"/>
Copied!

Calling a process

[SINCE Orbeon Forms 2019.1]
1
<fr:process-call
2
scope="oxf.fr.detail.process"
3
name="send"/>
Copied!
Attribute
Mandatory
Value
Comment
scope
Yes
property scope
name
Yes
process name
[SINCE Orbeon Forms 2019.1]
1
<fr:navigate
2
location="https://www.bbc.com/news"/>
Copied!
Attribute
Mandatory
Value
Comment
location
Yes
path or URL
target
No
_self or _blank or name of the browsing context
where to display the location

Setting the value of an attachment control

[SINCE Orbeon Forms 2019.1]
1
<fr:control-setattachment
2
control="..."/>
Copied!
Attribute
Mandatory
Value
Comment
control
Yes
control name
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:
1
<fr:control-setattachment
2
control="my-attachment"/>
Copied!
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>

Setting the filename of an attachment control

[SINCE Orbeon Forms 2019.1]
1
<fr:control-setfilename
2
control="..."
3
value="..."/>
Copied!
Attribute
Mandatory
Value
Comment
control
Yes
control name
value
Yes
value expression
value of the filename to set
This action allows setting the filename of an attachment control. Example:
1
<fr:control-setfilename
2
control="my-attachment"
3
value="'My Image.png'"/>
Copied!
This supports the following controls:
  • <fr:attachment>
  • <fr:image-attachment>

Setting the mediatype of an attachment control

[SINCE Orbeon Forms 2019.1]
1
<fr:control-setmediatype
2
control="..."
3
value="..."/>
Copied!
Attribute
Mandatory
Value
Comment
control
Yes
control name
value
Yes
value expression
value of the mediatype to set
This action allows setting the mediatype of an attachment control. Example:
1
<fr:control-setmediatype
2
control="my-attachment"
3
value="'image/png'"/>
Copied!
This supports the following controls:
  • <fr:attachment>
  • <fr:image-attachment>
Note that the <fr:control-setattachment> action automatically sets a mediatype.

Error handling

With Orbeon Forms 2018.2, errors when running services are silently ignored and the action continues.
With Orbeon Forms 2019.1, errors:
  1. 1.
    cause the entire action to stop.
  2. 2.
    run the oxf.fr.detail.process.action-service-error process
The default implementation of the service error process is as follows:
1
<property as="xs:string" name="oxf.fr.detail.process.action-service-error.*.*">
2
error-message("service-error")
3
</property>
Copied!
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.
1
<fr:data-iterate ref="/*/row">
2
<fr:service-call service="my-first-service">
3
<fr:value
4
value="foo"
5
ref="/some/path"/>
6
</fr:service-call>
7
<fr:service-call service="my-second-service">
8
<fr:value
9
expression-context="current-iteration"
10
value="bar"
11
ref="/some/other/path"/>
12
</fr:service-call>
13
</fr:data-iterate>
Copied!
To be more explicit, the attribute can also be set on the first <fr:value>:
1
<fr:data-iterate ref="/*/row">
2
<fr:service-call service="my-first-service">
3
<fr:value
4
expression-context="current-iteration"
5
value="foo"
6
ref="/some/path"/>
7
</fr:service-call>
8
<fr:service-call service="my-second-service">
9
<fr:value
10
expression-context="current-iteration"
11
value="bar"
12
ref="/some/other/path"/>
13
</fr:service-call>
14
</fr:data-iterate>
Copied!

See also

Last modified 3mo ago