home
products
education
support
partners
company

introduction

get started

articles

manual

tutorials

reference docs

case studies

knowledge base

goodies

screenshots

demos

echoes

Carousel zone


SourceForge.net Logo

home

forums

downloads

bugs

mailing list
XUI Zone - articles

number of ratings 0
average rating 0.00

Introducing Library Functions

Libraries of helpers and functions

One of the goals XUI is to help promote an MVC architecture. The Data Binding and Event Binding helps make this clean separation by putting the UI declaration in XML, separate from the business logic which is implemented in Java. One limitation of this mechanism is that the custom logic had to be routed through event handlers in classes derived from the XPage component.

This dependancy on a UI component was undesireable in some cases and made it a little more difficult to implement libraries of reusable functions than we would have liked. So, as of version 2.0 we have extended the attibute and event bindings to solve this problem.

Evaluated Attributes

Attributes within a XUI page can be specified dynamically, for example

In the above example we are recreating the simple calculator that we have used in other examples. While the example is a contrived (we will document some more realistic examples later) it shows the new syntax in action.

Line 5: Shows something similar to the pre XUI 2.0 syntax (which is still valid) except that the handler method is now in a separate class (com.xoetrope.library.Calculator) and package to the class implementing the page (com.mypackage.ui.swing.SimpleCalculator). The method being invoked is a static member of the class.

Line 6: Shows a similar call except that instead of a call to a static method a concrete instance of the class is constructed. Once the instance of the class is constructed it is labelled for subsequent use.

Line 7: Reuses the reference setup it line 6 and invokes a different method on the same object. The reference is project wide so the object associated with the name can also be used across pages.

Extended Event Handlers

The same syntax used for attributes is also used to extend the event bindings. The obvious difference is that an event binding sets up a reference to a method (the event handler method) and does not itself cause the method to be evaluated. The syntax for the extended event bindings is as follows:

  • mypackage.MyClass.myMethod to invoke a static method

  • mypackage.MyClass[].myMethod to create a new instance of the class on each evaluation

  • mypackage.MyClass[referenceName].myMethod for a named object instance

  • myMethod[referenceName] for a method contained with the invoking page

  • [referenceName].myMethod for a method contained with the class instance referred to by the reference name.

In the above example

Line 14 sets up an event binding to a static member of the com.xoetrope.library.Calculator class

Line 15 constructs a new instance of the class each time the event is bound (when the XML expression is loaded and evaluated).

Line 16 constructs a new instance and sets up a reference to the new instance. If the instance already existed it would be reused. In this case a instance of 'foo' had already been created at line 7 so that instance is reused instead of creating a new instance.

Lines 17 and 18 create bindings to other methods in the class and as in the case of line 16 they each use the 'foo' object created on line 7.

Expression Evaluators

The expressions are evaluated by an ExpressionEvaluator and each page has by default its own instance of the default expression evaluator. (The default evaluator delegates storage of the referenced classes to the project). However, the page allows this evaluator to be replaced and a different evaluator can be inserted. This replaceable evaluator allows a route to include other expression evaluators such as interpreters. As an example an evaluator for the Groovy language has been created. At present this evaluator is little more than a proof of concept.

comments


If you were logged in you could rate this article or add a comment.