-
8
pages
-
English
-
Documents
Description
Using GWT Generators for
databinding
An introduction to GWT Generat ors
Zenika ( www.zenika.com)
08/01/2007
by Jean-Philippe Dournel ( jean-philippe.dournel@zenika.fr)Preamble
The purpose of this tutorial is to explain how Deferred Binding works in GWT and the use of
the Generator class to create classes dynamically. The example we will use thoughout this
tutorial is the creation of an utility class which provides access to the properties of an object
using the field names. This mechanism will prove very useful for solving recurrent problems
like connecting a mode l to a GUI (also know as databinding).
Deferred Binding
In Java, reflection is a very powerful mechanism. Suppose we have two different classes,
Employee and Visitor, which are subclasses of Person and we want the object person to
indicate an instance of Emplo yee or Visitor according to the context.
In Java we would use reflection like this:
// status contains “Employee” or “Visitor”
String status = getStatus();
Person person = (Person) Class.forName(status).newInstance();
Thus, the instance held by the ob ject person is dy namically selected according to the character
string status.
For several reasons, reflection isn't possible with GWT. The first one deal with code
optimization: only methods and classes used in the application are translated into Javascript
during compilation. The other reason is that it is not possible to load a class dynamically in
Javascript.
To compensate this lack, GWT has ...
databinding
An introduction to GWT Generat ors
Zenika ( www.zenika.com)
08/01/2007
by Jean-Philippe Dournel ( jean-philippe.dournel@zenika.fr)Preamble
The purpose of this tutorial is to explain how Deferred Binding works in GWT and the use of
the Generator class to create classes dynamically. The example we will use thoughout this
tutorial is the creation of an utility class which provides access to the properties of an object
using the field names. This mechanism will prove very useful for solving recurrent problems
like connecting a mode l to a GUI (also know as databinding).
Deferred Binding
In Java, reflection is a very powerful mechanism. Suppose we have two different classes,
Employee and Visitor, which are subclasses of Person and we want the object person to
indicate an instance of Emplo yee or Visitor according to the context.
In Java we would use reflection like this:
// status contains “Employee” or “Visitor”
String status = getStatus();
Person person = (Person) Class.forName(status).newInstance();
Thus, the instance held by the ob ject person is dy namically selected according to the character
string status.
For several reasons, reflection isn't possible with GWT. The first one deal with code
optimization: only methods and classes used in the application are translated into Javascript
during compilation. The other reason is that it is not possible to load a class dynamically in
Javascript.
To compensate this lack, GWT has ...
-
Publié par
-
Langue
English