Apple WebObjects 5 User Manual

Page 6

Advertising
background image

6

Reviewer’s Guide

WebObjects 5

Today, most experts recommend using a template engine to generate web pages, an approach
that isolates the layout and formatting issues from the logic of the application. This separation
allows designers to create aesthetically pleasing HTML, and programmers to focus on efficiently
generated code.

WebObjects pioneered this idea (way back in 1996) with Web Components (sometimes called
WOComponents, after the class name). Web Components represent dynamic elements, which
can be either a complete page or a single item such as a table. WebObjects includes a vast
library of existing Web Components; you can easily subclass them to create your own library
of reusable components.

Originally developed to generate HTML files, Web Components can also be used to generate
XML or SMIL output, as well as to embed arbitrary client-side controls such as JavaScript. (SMIL
is an XML-compliant language used to describe interactive synchronized multimedia on the
web.) Because these templates use standard HTML, it’s easy to create output in any language,
including two-byte languages such as Japanese.

Each Web Component consists of an HTML file, a Java class, and a mapping file (which is just
another plist). The HTML file is standard HTML with the addition of special webobjects tag.
Each such tag refers to an entry in the mapping file, which defines a “WOAssociation.” A
WOAssociation uses various methods or instance variables in the associated Java class to
generate HTML. When the HTML file is parsed by the WebObjects template engine, the tags
are replaced by dynamic content from the associated class, using the WOAssociations.

These Java classes are automatically instantiated for each new session, and use Enterprise
Objects as their persistence mechanism. Thus, the developer generally only needs to write a
few lines of code covering each piece of application-specific business logic; all the session
management and persistence is handled automatically by WebObjects. The loose coupling
provided by the mapping file also makes it easy to update the Java code without having to
touch the HTML file (or vice versa).

Rich Java clients using EOAssociations

Sometimes an HTML interface isn’t rich enough or fast enough for interacting with large,
complex data sets. To address these situations, WebObjects supports the creation of three-
tier Java client applications using a technique called EOAssociations. An EOAssociation is a
bidirectional relationship between a user interface widget and an underlying data object.
EOAssociations are related to the WOAssociations used to manage the mapping in a Web
Component, except that EOAssociations can talk directly to the user interface, avoiding the
need for an intermediary.

The use of EOAssociations eliminates the need for the user interface to know about the web
server (or even the database server, for that matter). All the UI designer has to do is associate a
user interface widget with an appropriate data object, and the EOAssociation works with the
underlying frameworks to manage all the appropriate transport, caching, and persistence. In
particular, Java client applications maintain their own client-side object caches for optimum
performance. You can easily move logic between the client and the server for optimum security.

Web Components efficiently generate HTML, XML, or SMIL
output from reusable templates. This clearly separates the
presentation layer from your business logic and your data
model, allowing each piece to evolve independently.

When HTML isn’t enough, WebObjects makes it easy to create
highly interactive desktop clients using rich Swing widgets,
while still preserving the security and flexibility of three-tier
applications.

Advertising