Difference between revisions of "Variable Tag in QPR UI"

From Mea Wiki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
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 [[QPR UI System Variables|system context variables]] can be used.
+
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.
 
 
If the referenced context variable doesn't exist, an error is caused.
 
  
 
Variable tag contains following parameters:
 
Variable tag contains following parameters:
 
* '''name''': Name of the referenced context variable. This parameter is mandatory.
 
* '''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:
 
* '''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)
+
** '''none''': No escaping (this is default)
** '''json''': Escaping suitable for JSON string literals (characters to escape: " \, escape charater: '''\''')
+
** '''json''': Escaping suitable for JSON string literals (characters to escape: " \ and escape charater: '''\''')
** '''javascript''': Escaping suitable for JavaScript string literals (characters to escape: " ' \, 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: < > & " ', resulting strings: '''&amp;lt; &amp;gt; &amp;amp; &amp;quot; &amp;apos;''')
+
** '''xml''': Escaping suitable for xml text nodes (characters to escape: < > & " ' and resulting strings: '''&amp;lt; &amp;gt; &amp;amp; &amp;quot; &amp;apos;''')
** '''html''': Encoding that the following JavaScript code performs: '''$('<<nowiki />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.
+
** '''html''': Encoding performed by the following JavaScript code: '''$('<<nowiki />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)
 
** '''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)
 
** '''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:
 
Examples:
* <#variable name="variable1">
+
<pre>
* <#variable name="variable1" escape="json">
+
<#variable name="variable1">
* <#variable name="someJsonDataVar" jsonpath="$.store.book[0].title">
+
<#variable name="variable1" escape="json">
 +
</pre>
  
=== Short syntax for Variable tag ===
+
If the referenced context variable doesn't exist, an error is caused.
There is also the following '''short syntax''' for the Variable tag:
 
  
 +
=== 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">'''
 
* '''{#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.
+
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.
 
 
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.
 
  
 
[[Category: QPR UI]]
 
[[Category: QPR UI]]

Latest revision as of 20:46, 16 May 2019

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.