Search code examples
orbeonxforms

Using an instance's value for a dispatch name


I have the following event handler and instance:

<xforms:action ev:event="test-event">
    <!-- do some stuff in here -->
</xforms:action>

<xforms:instance id="metadata">
    <dummy />
</xforms:instance>

Later, I have:

<xforms:setvalue ref="instance('metadata')" value="'test-event'" />
<xforms:dispatch name="instance('metadata')" target="somethingElse" />

How do I get the dispatch to fire off the event with name based on the value in the metadata instance? (In this case, to fire off the test-event event?)


Solution

  • You can use an AVT in the name attribute. That is, if the value is between curly brackets, it will be evaluated as an XPath expression instead of being taken literally. For instance, you could write:

    <xf:trigger id="my-trigger">
        <xf:label>Click me!</xf:label>
        <xf:message ev:event="my-event" value="'Got it!'"/>
        <xf:dispatch ev:event="DOMActivate" name="{concat('my', '-', 'event')}" target="my-trigger"/>
    </xf:trigger>