Creating or configuring forms > Configuring the <components> element > Setting component rules > Getting component rule responses dynamically

6.1.18.2 Getting component rule responses dynamically

Viewpoint can make a remote procedure call (RPC) that executes a script on the Web server to determine a component's response. In such a case, when the component rule is evaluated to true, the script specified in the XML configuration executes. Upon completion, that script returns XML describing another type of component response, which then runs on the client. This makes it possible to perform more complex operations to change the user interface state dynamically.

To get a component rule's response dynamically

  1. When setting rules for a component (see Setting component rules), insert the <response> element inside of the <component-rule> element.
  2. Set the source attribute to either "file" or "exec".
  3. Attribute Description
    "file" Viewpoint reads the contents of the file and attempts to parse it to any other component response. The file's contents should be in XML format, as defined in all other component response options.
    "exec" Viewpoint executes the file on the Web server and parses the STDOUT of the file into one of the component response options.
  4. If the source of the dynamic component response is a script (source="exec"), specify required input parameters using the <input> element.
  5. Set one or more <component id="X"> elements, configuring id to correspond to the component required.
  6. <component-rule>
      <requirement>
        <component id="enable-firewall-checkbox" />
      </requirement>
      <response source="exec">
        <url value="file:///home/user/tools/getFirewallOptions.py" />
        <input>
          <component id="ip-address" />
        </input>
      </response>
    </component-rule>

    The getFirewallOptions.py script requires the value of the "ip address" component. When the user clicks the appropriate checkbox, the script is called in the following manner (assuming the ip address is 192.168.99.120):

    /home/user/tools/getFirewallOptions.py xml='<components> <component id="ip-address"> <value>192.168.99.120"</value> </component> </components>

    The script returns XML respresenting a component response like the following:

    <response>
      <component id="LAN-options">
        <display>true</display>
      </component>
      <component id="WAN-options">
        <display>false</display>
      </component>
    </response>

Related topics