Difference between revisions of "Variable Tag in QPR UI"

From Mea Wiki
Jump to navigation Jump to search
Line 20: Line 20:
 
* <#variable name="someJsonDataVar" jsonpath="$.store.book[0].title">
 
* <#variable name="someJsonDataVar" jsonpath="$.store.book[0].title">
  
=== Short syntax for Variable tag ===
+
=== Short syntax for variables ===
There is also the following '''short syntax''' for the Variable tag:
+
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">'''
 
* '''{#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.
+
Notes:
 
+
* In the short syntax, it's not possible to use parameters, such as escaping.
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.
+
* If the referred variable contains spaces, it's not possible to use the short syntax.
  
 
[[Category: QPR UI]]
 
[[Category: QPR UI]]

Revision as of 07:34, 26 January 2018

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: " \ 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)
  • 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 variables

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">

Notes:

  • In the short syntax, it's not possible to use parameters, such as escaping.
  • If the referred variable contains spaces, it's not possible to use the short syntax.