You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Mind Bridge <mi...@yahoo.com> on 2005/12/28 19:14:34 UTC
Polymorphism, Action service, rewind (was [DISCUSS] Moving beyond
the "rewind cycle" in Tapestry 4.1)
One very typical use of OOP with user interfaces is to ask the object
itself to provide its user interface. This approach has a number of
advantages, but most prominently it provides proper UI support via
polymorphism, as the UI can be specific to the object.
Here is a simple example:
Suppose you have a base Setting type that is inherited by the classes
StringSetting, IntegerSetting, DateSetting, etc.
There is a service that returns a List of Setting objects in the
database. The objects are of one of the types listed above. You have to
create a UI that allows you to edit the objects in the list.
Ideally you would have separate domain and view objects, but to keep the
example simple, let assume that the objects perform both roles
If the OOP approach is followed, the Setting object would have an
abstract function like this:
IRender getEditView(IRequestCycle, IEditSettingListener)
That function will be implemented in the specific subclass (e.g.
StringSetting) to return a UI that allows editing of the object. The UIs
will normally contain a form that will eventually invoke method(s) in
IEditSettingListener when submitted.
The Tapestry template for the page then becomes something like this:
<span jwcid="@For" source="ognl:settings" value="ognl:setting" ...>
<span jwcid="@Delegator"
delegate="ognl:setting.getEditView(requestCycle, #root)"/>
</span>
Note that this solution will support other types of Setting objects (not
currently known ones too) without modifications and this is a natural
consequence of using the OOP approach.
Consider the following points:
1) IEditSettingListener usually points to an object that is not
serializable. Some kind of a rewind is needed in order to obtain its value.
There is a solution in a limited number of cases where the
implementation of IEditSettingListener is a service accessible via
HiveMind (for example) and a serializable proxy is passed to
getEditView(). Unfortunately that would work only in some cases.
The issue of objects that are not serializable or services that have
non-serializable contexts occurs in many other situations as well. Is
there a proper solution that does not involve rewind?
2) Depending on where the form is, the Action service may be necessary
for the component returned by getEditView() to have access to the page
in which it was included. Without it, the page would not even be loaded
(because of the dynamic, rather than the static coupling between the
two). This applies to both form submission and to links that the dynamic
component may contain.
In other words, the price for the static approach that Tapestry takes is
that it must have Action to support the dynamic elements as well.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org