Xoetrope
HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Advanced Event Handling


Evaluated Attributes
The event handler mechanism can use the evaluated attribute mechanism to give you more control over how events are handled. The mechanism can reference the methods of some of the main objects with some special keywords.

1 ${this[componentName].methodName()} refers to the method methodName of a component on the page with the component name componentName, for example ${this[myBtn].show()} calls the hidemethod of the myBtn button object.

2 ${this.methodName()} refers to the page itself, so for example ${this.showPage("foo")} calls the page's showPage method. Of course the this reference is largely redundant.

3 ${project.methodName()} refers to the current project or the project that owns the page. This type of reference is of little use to most users and is therefore of most interest if and when the projects are customized.

4 ${className[reference].methodName()} refers to the page itself, so for example ${my.package.MyClassHelper[MyHelper].myMethod("foo")} calls the MyClassHelper's myMethod method. If an instance of the class is not already available then a new instance will be instantiated and stored under the reference name. On subsequent calls the reference will be looked up and reused, and as a shortcut the classname can be omitted for subsequent calls, so for a second call one could specify ${[MyHelper].myMethod("foo")}.

The responsibility for ensuring that the object has been instantiated rests with the developer if this shorthand is used. Within a single page it may not be safe to use such a reference as the object is not instantiated till it is required. In a multipage context the shorthand may be safely used if the object has already been created, and the object created by the earlier pages will be reused by the subsequent pages.

External Event Handlers
Using the syntax (4) above it is possible to reference an external class. However, if you do not want to let that evaluator instantiate that class you can explicitly create the object and store the reference before the evaluator needs the object reference. The references are stored in a Hashtable owned by the project under the name UserClassReferences, thus you can retrieve the store and add your object reference:

  MyHelper myHelper = new MyHelper();
  Hashtable references = (UserClassReferences)project.getObject( "UserClassReferences" );
  references.put( "myHelper", myHelper );

There are no comments on this page. [Add comment]

Page was generated in 0.1562 seconds