variable-resolver"

From Documentation
Line 1: Line 1:
== The variable-resolver Directive ==
+
 
  
 
<source lang="xml" >
 
<source lang="xml" >

Revision as of 01:30, 9 July 2010


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

Specifies the variable resolver that will 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"?>

class

[Optional]

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.

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.

On the hand, you, with ZK 3.6.2 or later, can use any readable name for arguments as follows.

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