Reference Manual for Gracelets - 2.0.0.RC2SourceForge.net Logo
5.3 - Framework : Binding Resolvers
The API for getting involved with the way variables are resolved from gracelet scripts is in the gracelets.api.binding package. The base interface gracelets.api.binding.GraceletBindingResolver. This interface is defined as follows:

GraceletBindingResolver.java
Toggle Line Numbers
1 package gracelets.api.binding; 
2  
3 /** 
4  * This is the basic contract/interface for binding resolvers, that can be used as a part 
5  * of variable resolution. 
6  * 
7  * @author elponderador 
8  * @author $Author: ponderator $ 
9  * @version $Id: GraceletBindingResolver.java 1699 2009-07-09 17:55:47Z ponderator $ 
10  */ 
11 public interface GraceletBindingResolver { 
12  
13     /** 
14      * @param key The key whose corresponding value should be retrieved 
15      * @return Returns the value, which can be null, and thus null does not mean the value is not actually set 
16      */ 
17     Object resolve (Object key); 
18      
19     /** 
20      * This is used to assign a value to a key. {@link GraceletBindingResolver#canAssign(Object)} should be 
21      * called first in order to know if this method will be successful. 
22      *  
23      * @param key The key to assign to the value 
24      * @param value The value to assign to the key 
25      */ 
26     void assign (Object key, Object value); 
27      
28     /** 
29      * If this returns false, {@link #assign(Object, Object)} should not be called. 
30      *  
31      * @param key The key to validate 
32      * @return Returns true if this resolver can retrieve a value for the key, otherwise false 
33      */ 
34     boolean canAssign (Object key); 
35      
36 } 
Every gracelet script's binding uses a composite binding resolver to get/set undeclared variable references. The default gracelets implementation defines a set of binding resolvers, used together in the composite binding resolver in the order they are added. These are as follows:
StandardBindingResolver
This binding resolver is used to provide access to common components of the gracelets/jsf/facelets system. You can get a list of them in the
appendix

VariableMapperBindingResolver
This allows variables that are declared and passed to facelet/gracelet templates to be resolved contextually.

BuilderContextBindingResolver
This allows the variables during building passed by tag handler to be resolvable for groovy tag source files.

VariableContextBindingResolver
This allows gracelet scripts to access the variable context (scopes like view, conversation, session, etc.,). This is the only resolver that allows assignment, in regards to the interface canAssign() and assign() methods. This allows scripts to be able to "outject" undeclared variables into the variable context scopes.

ELBindingResolver
This will make sure that you can access EL based objects like JSF managed beans defined inside faces-config.xml

LibraryBindingResolver
This allows one to access variables available via ScriptBindings defined in
Gracelet Component Libraries.

ExtensionBindingResolver
This allows
framework extensions to be able to participate in variable resolution.

LibraryAliasBindingResolver
When a Gracelet Component Library has an alias this binding allows that alias to be used to access it instead of the namespace.

This api is available mainly for those who want to add fundamental script binding resolution to the core framework, since if all you want to do is provide a few variables to your gracelets scripts you can use ScriptBindings defined in a Gracelet Component Library. Also if you are integrating Gracelets into your own framework, you can define a set of binding resolvers and add them in the order you want them to be resolved in, even mixing some of the default Gracelet implementations if you want to. This would be done inside the implementation of the GraceletsPhaseListener.