How Tapestry Deals objects in HTML

One of the features that really makes Tapestry stand out is "objects is objects". In order to support this very cool feature, Tapestry must represent an object using text when the object is part of an HTML page. The DataSqueezer has the job of outputing text for objects on the way out the door, and input objects from text on the way in the door.

The DataSqueezer works by examining the class and interface hierachy of the Object looking for a registred implementation of the ISqeezeAdaptor interface. The Serializable interface is registred with the DataSqueezer.

DataSqueezer can use the Serializeable Interface

The ISqueezeAdaptor implementation for the Serializable interface does the following:

Serializable Object Outbound to an HTML page

The data is serialized to a byte stream.

The byte stream is Base64 encoded.

The Base64 encoded data is sent out the door

Serializable Object Inbound from an HTML request

Another DataSqueezer tactic

A Base64 encoded byte stream can be quite a bit of text. So, another route you can go is registering your own DataSqueezer that does what ever you want. For instance, the following example does this for objects rarely changing configuration stored in a database. On the way out, the ISqueezeAdaptor encodes information needed by an ORM to load it from the database including the class and object identifier. On the way in, the ISqueezeAdaptor decodes the class and object id from the string and asks the ORM to load the object.

Tapestry takes care of calling the DataSqueezer so all your application ever does is reference an object.

There are a couple of tricks to constructing a DataSqueezer ISqueezeAdaptor.

Example PropertySelection using Data Squeezer

This example shows how create a DataSqueezer enabled PropertySelection. DataObject is the base class for all the squeezeable objects, and DataObjectAdaptor is the squeeze adaptor that uses a orm service to load and save DataObjects. In contrast to the first example, the adaptor class is not anonymous because it is used both here and in the engine class (not shown).