Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > WebObjects Developer's Guide


Table of Contents Previous Section

How Client-Side Components Work

A client-side component is really just a special case of a particular server-side dynamic element named WOApplet. You use WOApplet when you want to include any Java applet in a WebObjects application. The difference between a client-side component and other Java applets is that client-side components can communicate with the server.

When you look at client-side component's bindings in the .wod file, it looks like this example:

INPUTFIELD : WOApplet {
code = "next.wo.client.controls.TextFieldApplet.class";
codebase = "/WebObjects/Java";
archive = "woextensions.jar";
agcArchive = "woextensions.jar";
width = "200";
height = "20";
associationClass = "com.apple.client.webobjects.SimpleAssociation";
stringValue = inputString
};
Like any other server-side dynamic element, the WOApplet's definition contains a list of attributes bound to constants or variables in the component's code.

The code attribute specifies which client-side component this WOApplet should download. The codebase attribute specifies the path of the component relative to your web server's document root. (For the provided client-side components, this path is always /WebObjects/Java.)

The archive attribute specifies .jar files that should be pre-loaded onto the client machine. If you don't use this attribute, the applet downloads Java .class files from the server one by one as it needs them. With the archive attribute, you can package all necessary Java classes into archive files, and they are downloaded once. However, only web browsers that have Java 1.1 support can use .jar files. Because Java 1.1 is fairly new, there's a good chance your users use browsers that don't support .jar files. All of the provided client-side components are packaged in a single archive file named woextensions.jar.

The agcArchive and associationClass attributes differentiate the client-side components from any other applet you might include in your application. The agcArchive attribute specifies the .jar file that contains the AppletGroupController object. AppletGroupController is a hidden Java applet (on the client) that controls the visible applets and handles communication back to the server. AppletGroupController works in conjunction with the object specified by the association attribute. The association attribute specifies a subclass of com.apple.client.webobjects.Association that the component uses to communicate with the application on the server. The Association object can get and set component state and cause methods to be invoked in the server when actions are triggered in the client. The most common association is com.apple.client.webobjects.SimpleAssociation. When creating your own client-side components, you can either use it or define your own association. Creating your own association is useful when you don't have the source code for your client-side component.

The final attribute, stringValue, is an attribute specific to the TextFieldApplet component. The Association object assigns the value of the inputString variable to be the value of the text field on the client and keeps the two objects in sync so that they always have the same value.

Note: Netscape Navigator 4 supports only a single .jar file per applet, and if there is an interface class to support the applets (that is, if you are using AppletGroupController), that object must be found in the same archive file. Thus if you must support Netscape Navigator 4, you should create one .jar file that contains all of your Java client-side classes, all third-party classes that you are using, and all classes in com.apple.client.webobjects. Bind that .jar file to the archive attribute of all of the WOApplets on your page. Bind the same .jar file to the agcArchive attribute of the first WOApplet on the page.

Table of Contents Next Section