Choosing a strategy – Apple WebObjects 3.5 User Manual

Page 143

Advertising
background image

143

In earlier chapters, you learned about client-side Java components. Client-
side components are Java applets that your application can use instead of
server-side dynamic elements to interact with users. WebObjects comes
with several premade client-side components. To use them you simply add
them to your application in much the same way that you add a server-side
dynamic element.

You can create your own client-side component if the premade components
don’t suit your needs or if you already have a Java applet that you would like
to use as a client-side component. This chapter describes how to do so.

Choosing a Strategy

You can create a client-side component out of any Java applet, provided you
know some details about it. You must know the applet’s accessor methods
for setting and getting state, and you must know how to detect when the
applet has triggered an action (for applets that trigger actions). How you
create a client-side component depends on whether you have source code
for the applet.

If you don’t have the applet’s source code, you must create your own
subclass of

next.wo.client.Association

. As explained in “How Client-Side

Components Work” (page 38), client-side components use an Association
object to communicate with the component on the server. Associations can
extract values from the client-side component, set values in the client-side
component, and trigger action methods on the server.

If you do have the source code, you may still want to provide your own
subclass of Association. However, you’re more likely to want to use the
provided subclass SimpleAssociation (which is what all of the client-side
components packaged with WebObjects use). The benefit of using
SimpleAssociation is that it uses an AppletGroupController object.
AppletGroupController is a hidden Java applet (on the client) that controls
the visible applets and handles communication back to the server (see
Figure 37). The AppletGroupController accesses each of the applets on the
page using an Association. It is through these Associations that the data or
state each applet manages is passed to the AppletGroupController and,
through it, to the server. When an Association fires its applet’s action, the
AppletGroupController does what is necessary to ensure that the bound
method in the server is invoked. An AppletGroupController, once
downloaded, knows what class of Association to use and what the

Advertising