OpenWGA 7.9 - WebTML reference

WebTML tags

<tml:action>

Description :
Defines a TML action.

A TML action is a TMLScript code block which is executed as result of an user interaction for e.g. via <tml:button>. In the default behavior the script code gets executed and the current page will be reloaded.
Derived from: Attributes:
show inherited attributes ...
Name Value(s) Purpose
async true | false This attribute is only valid if master='true' and defines if the action should be executed asynchronous or not.
debounce true | false Activates or deactivates the debounce feature of the action.
id action-id ID for the action which should be defined.
master true | false Defines if the action should be called with master level or not.
plainlink true | false Only valid if the action tag generates an action link. If the action link is defined within a TML form the form will normally be submitted before the action is called. plainlink='true' enforces to call the action via a GET request. No POST request will be used and unsaved form data will be discarded.
ref action-id | tmlscript-module-reference Defines the 'action id' or 'TMLScript module reference' to generate an action link for.

Details:
A <tml:action> tag has two modes to either define a new action or to or execute an existing action via JavaScript.

To define an action the tag must specify an id and contain the TMLScript code to execute in the contents of the tag. In this mode the attributes specifying action definition types like async, master etc. are valid.

To execute an action via JavaScript it must specify the id of the action to call in the ref attribute. In this mode all attributes inherited from <tml:[All action calling tags]> are valid. The tag will produce a string called "action link" which can be used as parameter for JavaScript function callAction() to call the action from JavaScript.

WebTML Actions can also be defined as separate TMLScript modules in the OpenWGA design, which in most cases should be preferred. <tml:action> then however can be used to call these actions from JavaScript.

Examples:
Example 1 using <tml:action> to define an action. The action gets the id "writeToProfile" and can be called by a simple HTML link built by <tml:url>:

<tml:action id="writeToProfile">
profile.setitem("aNumber", 4711);
profile.save();
</tml:action>

<a href="<tml:url action="writeToProfile"/>">save</a>


Example 2 using <tml:action to call an action defined as TMLScript module. By separating action call and definition you more clearly separate business logic from layout. First the code of the module "writeToProfile.tmlscript" in folder "actions":
profile.setitem("aNumber", 4711);
profile.save();


The following is the definition of a JavaScript function that calls the action. It must be contained in a WebTML module and not in a JavaScript module to let it process the <tml:action> tag. After a client side confirmation the action is executed by the callAction function which receives the data of the action to call from <tml:action>.

function callTheAction() {
  if (confirm("Are you sure?")) {
    callAction("<tml:action ref="actions:writeToProfile"/>");
  }
}


Note two things in the code above which are important:
  • The TMLScript module "writeToProfile" is referenced by omitting the ".tmlscript" suffix and specifying the file system path with colons ":" as path separators
  • The whole return value of the <tml:action> call is surrounded by double quotes so it forms a string in JavaScript.