<tml:action>

Avaliable since version 2.0.2

Description:
Defines a TML-Action. TML-Actions are TMLScript-Functions, that are invoken, when a Link referencing the action, is clicked (see <tml:url/>). When clicking, the page is loaded anew and the TMLScript code is executed before re-rendering the page content.
Attributes:
General WebTML attributes are hidden -> show general attributes
Name Value(s) Version Usage

Details:
There are three options of usage:

1. An action can be predefined via <tml:action> and be referenced by other tags on the WebTML-Page, e.g. <tml:url/> or other <tmL:action/>-Tags, to create URLs to invoke the action. In this option, the <tml:action>-Tag does no output itself but only defines the action . Therefore the action is given an ID (see Example 1)

The following options are new since WGA Publisher 2.1.1

2. A <tml:action>-Tag can be used, tro create actions invoked by client side JavaScript. The tag therefor creates a so called "Action-Link". This is a text code, containing everything necessary to invoke the action. This text can be passed to a JavaScript function "callAction" (that is predefined via WebTML-Element "htmlhead"), as a parameter, to invoke the action. "callAction" can be invoked by any JavaScript code. To choose this option, the ID attribut is either omitted, or the attribute output="true" is explicitly set. (see Example 2)

3. As a variant to option 2, the <tml:action>-Tag can reference other actions, instead of defining them itself. Is an action defined via Option 1 and should be used in client side JavaScript code later, the action tag gains another attribute "ref", containing the ID of the action to be invoked. In this option, the <tml:action>-tag can also contain parameters for the action via attributes param1 to param5. (see Example 3)
Examples:
    Example 1:

      <tml:action id="odor">
        this.profile.setitem("odor", 4711);
        this.profile.save()
      </tml:action>
      <a href="<tml:url type="action" action="odor"/>">Write to Profile</a>

      Creates a link with label "Write to profile".
      When clicking this link, the page is called again, and the TMLScript-Action is invoked before rendering. In this case, the value 4711 is written to the field "odo" in the profile document.
    Example 2:
      <select name="choice" onchange="callAction('<tml:action>this.setSessionVar("currentChoice", this.tmlform.choice);</tml:action>')">
      <option value="xxx">....
      </select>

      In this example an TML-Action should be called, when the content of a HTML-Choice field changes. For this purpose, the JavaScript event "onChange" calls the JavaScript function "callAction". This is predefined by WebTML-Element "htmlhead", that should be included in every HTML-Page. As a parameter a string is passed to that function, that is generated by the <tml:action>-Tag. it should be noted, that therefor the <tml:action>-Tag is surrounded by single quotation marks ('). The contents of the tag defines the action, that is executed be calling "callAction".

    Beispiel 3:
      <!-- Action to store the form -->
      <tml:action id="validateAndSave">

      if (this.tmlform.firstname == '') {
      this.setvar("error", "The first name must be entered");
      }
      else if (this.tmlform.surname == '') {
      this.setvar("error", "The surname must be entered");
        }
        else {
        this.tmlform.storeInProfile();
        }

      </tml:action>

      <!-- Output of error message -->
      <p style="color: red"><tml:item name="error"/></p>

      <!--- The form -->
      <tml:form id="names">
        First Name: <tml:input name="firstname"/><br/>
        Surname: <tml:input name="surname"/><br/>

        <button onclick="callAction('<tml:action ref="validateAndSave"/>')">Store</button>
      </tml:form>

      In this example a form should be stored by a TML-Action. The action additionally executes some validations, if the fields "firstname" and "surname" are filled. First the action "validateAndSave" is defined, as known from example 1. In the form finally a button is defined with event "onClick" calling the JavaScript function "callAction". As in example 2 the <tml:action>-Tag will generate the string parameter for this function. But different than there, the action is not defined "in place", but the predefined action "validateAndSave" is referenced via ref-Attribute.

      Easier to use, but less customizable, functionalities for invoking actions when select field changes values or clicking a button are provided via the followingWebTML-Tags and Attributes
      <tml:input type="select" changeaction="actionid"/>
      <tml:button clickaction="actionid"/>