Variable Tag in QPR UI

From Mea Wiki
Revision as of 13:30, 7 November 2017 by Ollvihe (talk | contribs)
Jump to navigation Jump to search

Variable tag references to a context variable, i.e. when the tag is evaluated, the tag is replaced by the context variable value. The value is taken from the effective context of that UI element, where the tag resides. When the referenced context variable value changes, the UI element, which setting contain the variable tag, is also refreshed. Variable tag is not able change the context variable value. Also system context variables can be used.

If the referenced context variable doesn't exist, an error is caused.

Variable tag contains following parameters:

  • name: Name of the referenced context variable. This parameter is mandatory.
  • escape: Determines which escaping or encoding is added to the context variable value when the value is used. This parameter is needed, so that the value is compatible with its context, e.g. inside string literal quotation marks. Following values can be used:
    • none: No escaping (default value)
    • json: Escaping suitable for JSON string literals (characters to escape: " \, escape charater: \)
    • javascript: Escaping suitable for JavaScript string literals (characters to escape: " ' \, escape charater: \)
    • xml: Escaping suitable for xml text nodes (characters to escape: < > & " ', resulting strings: &lt; &gt; &amp; &quot; &apos;)
    • html: Encoding that the following JavaScript code performs: $().text("textToEncode").html();. Html encoding is needed when a text is put in a html code and the text should not be interpreted as html.
    • uri: Escaping suitable for full url's. Implements JavaScript encodeUri() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
    • uricomponent: Escaping suitable for url address pars such as parameters. Implements JavaScript encodeUriComponent() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
  • jsonpath: Contains a JSON path expression (more information: https://github.com/json-path/JsonPath). Context variable value is expected to contain a JSON value and instead of replacing the whole JSON value, the JSON path expression is evaluated for the JSON value and the result is replaced. (will be used in future)

Examples:

  • <#variable name="variable1">
  • <#variable name="variable1" escape="json">
  • <#variable name="someJsonDataVar" jsonpath="$.store.book[0].title">

Short syntax for Variable tag

There is also the following short syntax for the Variable tag:

  • <#var1> is same as <#variable name="var1">
  • {#var1} is same as <#variable name="var1">

The short syntax differs from normal tags in a way that the short syntax doesn't contain parameters, whereas normal tags always have at least one parameter. The short syntax is identified by the tag parser only if it's properly written, i.e. there are no error messages for incorrectly defined short syntax.

Note on context variables that contain spaces: When using <#var1> syntax, it's not possible to refer to context variables that use spaces. Using the {#var1} syntax, spaces are possible.