variable-resolver"

From Documentation
m
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
   [''arg0''="..."] [''arg1''="..."] [''arg2''="..."] [''arg3''="..."]?>
 
   [''arg0''="..."] [''arg1''="..."] [''arg2''="..."] [''arg3''="..."]?>
  
Specifies the variable resolver that will be used by the <tt>zscript</tt> interpreter and the EL expressions to resolve unknown variables. The specified class must implement the <javadoc type="interface">org.zkoss.xel.VariableResolver</javadoc> interface.
+
Specifies the variable resolver that could be used by the <code>zscript</code> interpreter and the EL expressions to resolve unknown variables. The specified class must implement the <javadoc type="interface">org.zkoss.xel.VariableResolver</javadoc> interface.
  
You can specify multiple variable resolvers with multiple <tt>variable-resolver</tt> directives. The later declared one has higher priority.
+
You can specify multiple variable resolvers with multiple <code>variable-resolver</code> directives. The later declared one has higher priority.
  
Notice that the <tt>variable-resolver</tt> directives are evaluated before the <tt>init</tt> directives, so the <tt>zscript</tt> codes referenced by the <tt>init</tt> directives are affected by the variable resolver.
+
Notice that the <code>variable-resolver</code> directives are evaluated before the <code>init</code> directives, so the <code>zscript</code> codes referenced by the <code>init</code> directives are affected by the variable resolver.
  
 
The following is an example when using ZK with the Spring framework. It resolves Java Beans declared in the Spring framework, such that you access them directly.
 
The following is an example when using ZK with the Spring framework. It resolves Java Beans declared in the Spring framework, such that you access them directly.
Line 17: Line 17:
 
</source>
 
</source>
  
 +
Notice that if you have a variable resolver used for every page, you don't have to declare it on every page. Rather, you could register a system-level variable resolver. For more information, please refer to [[ZK Developer's Reference/UI Composing/ZUML/EL Expressions#System-level_Variable_Resolver|ZK Developer's Reference: System-level Variable Resolvers]].
 
= class =
 
= class =
  
  [Optional]
+
  [Required]
  
A class name that must implement the <javadoc type="interface">org.zkoss.xel.VariableResolver</javadoc> interface. Unlike the <tt>init</tt> directive, the class name cannot be the class that is defined in zscript codes.
+
A class name that must implement the <javadoc type="interface">org.zkoss.xel.VariableResolver</javadoc> interface. Unlike the <code>init</code> directive, the class name cannot be the class that is defined in zscript codes.
  
 
= arg0, arg1... =
 
= arg0, arg1... =
Line 33: Line 34:
 
# Foo()
 
# Foo()
  
If the first signature is found, the arguments with the name and value are passed to the constructor as an instance of <tt>Map</tt>. If the second signature is found, the values of arguments are passed to the constructor as an array of objects.
+
If the first signature is found, the arguments with the name and value are passed to the constructor as an instance of <code>Map</code>. If the second signature is found, the values of arguments are passed to the constructor as an array of objects.
  
 
<source lang="xml">
 
<source lang="xml">
Line 41: Line 42:
 
will cause <code>Foo(Map args)</code> being called with a map, which has an entry: <code>whatever=anything</code>. If not found, <code>Foo(Object[] args)</code> will be called with a single-item array and the value of the item is <code>anything</code>.
 
will cause <code>Foo(Map args)</code> being called with a map, which has an entry: <code>whatever=anything</code>. If not found, <code>Foo(Object[] args)</code> will be called with a single-item array and the value of the item is <code>anything</code>.
  
Prior to ZK 3.6.2, only the second signature is checked if one or more argument is specified, and it assumes <tt>arg0</tt> as the first argument, <tt>arg1</tt> as the second, and so on.
+
Prior to ZK 3.6.2, only the second signature is checked if one or more argument is specified, and it assumes <code>arg0</code> as the first argument, <code>arg1</code> as the second, and so on.
  
=Version History=
 
  
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZUMLReferencePageFooter}}
 
{{ZUMLReferencePageFooter}}

Latest revision as of 05:36, 8 April 2024



Syntax:

<?variable-resolver class="..." 
  [arg0="..."] [arg1="..."] [arg2="..."] [arg3="..."]?>

Specifies the variable resolver that could be used by the zscript interpreter and the EL expressions to resolve unknown variables. The specified class must implement the VariableResolver interface.

You can specify multiple variable resolvers with multiple variable-resolver directives. The later declared one has higher priority.

Notice that the variable-resolver directives are evaluated before the init directives, so the zscript codes referenced by the init directives are affected by the variable resolver.

The following is an example when using ZK with the Spring framework. It resolves Java Beans declared in the Spring framework, such that you access them directly.

 <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>

Notice that if you have a variable resolver used for every page, you don't have to declare it on every page. Rather, you could register a system-level variable resolver. For more information, please refer to ZK Developer's Reference: System-level Variable Resolvers.

class

[Required]

A class name that must implement the VariableResolver interface. Unlike the init directive, the class name cannot be the class that is defined in zscript codes.

arg0, arg1...

[Optional]

You could specify any number of arguments. If not specified, the default constructor is assumed. If specified, it will look for the constructor with the signature in the following order:

  1. Foo(Map args)
  2. Foo(Object[] args)
  3. Foo()

If the first signature is found, the arguments with the name and value are passed to the constructor as an instance of Map. If the second signature is found, the values of arguments are passed to the constructor as an array of objects.

<?variable-resolver class="foo.Foo" whatever="anything"?>

will cause Foo(Map args) being called with a map, which has an entry: whatever=anything. If not found, Foo(Object[] args) will be called with a single-item array and the value of the item is anything.

Prior to ZK 3.6.2, only the second signature is checked if one or more argument is specified, and it assumes arg0 as the first argument, arg1 as the second, and so on.




Last Update : 2024/04/08

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.