Variable Tag in QPR UI

From Mea Wiki
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.

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 (this is default)
    • json: Escaping suitable for JSON string literals (characters to escape: " \ and escape charater: \)
    • javascript: Escaping suitable for JavaScript string literals (characters to escape: " ' \ and escape charater: \)
    • xml: Escaping suitable for xml text nodes (characters to escape: < > & " ' and resulting strings: &lt; &gt; &amp; &quot; &apos;)
    • html: Encoding performed by the following JavaScript code: $('<div/>').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)

Examples:

<#variable name="variable1">
<#variable name="variable1" escape="json">

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

Short syntax for variable referencing

There is also the following short syntax to refer to variables:

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

In the short syntax, it's not possible to use parameters, i.e. the escaping. In addition, if the referred variable contains spaces, it's not possible to use the short syntax.