Documentation Archive Developer
Search
PATH  WebObjects 4.0 Documentation > WebObjects Programming Topics

Extending Dynamic Elements

Synopsis

Describes how to implement custom dynamic elements using components.

Discussion

Custom dynamic elements in WebObjects are built in one of two ways: based on a component or subclassed from WODynamicElement. A custom dynamic element based on a component consists of a HTML, a WOD and a WebScript file. The HTML file specifies how this dynamic element looks. The WOD file declares the WebObjects dynamic elements comprising the custom dynamic element. The WOS file implements the dynamic element. As an example, we will build a dynamic element MyText which is a HTML form text input with a description above it to act as a hint of what to enter.

Figure 1. MyText.HTML
<font size="2"><webobject name=AHint></webobject></font>
<webobject name=AText></webobject>
Figure 2. MyText.WOD
AHint: WOString
{
	value = hintValue;
};
AText: WOText
{
	value = stringTextValue;
	rows = rowValue;
	cols = colValue;
	escapeHTML = escapeHTMLValue;
};
Figure 3. MyText.WOS
id hintValue, rowValue, colValue, stringTextValue, escapeHTMLValue;

 

We will use the MyText dynamic element to input a headline. The following declarations are made in the WOD file.

Figure 4. WOD file
Headline: MyText
{
	stringTextValue = myDocument.headline;
	hintValue = "enter Headline here";
	rowValue = "2";
	colValue = "50";
escapeHTMLValue = NO;
};

 

When the Headline element is displayed, "enter Headline here" appears on the top and the HTML form text field appears on the bottom.

To build a custom dynamic element subclassed from WODynamicElement, you must declare the variable bindings for your custom dynamic element as WOAssociation. For example,

Figure 5. Objective-C Code
@interface WOSubscribePanel : WODynamicElement
{
    WOAssociation * emailAddress;
    WOAssociation * subscribeAction;
}

 

You must also implement the following three methods:

Figure 6. Objective-C Code
- (id)initWithName:(NSString *) aName associations:(NSDictionary *) 
   someAssociations template: (WOElement *) aTemplate;
- (void)takeValuesFromRequest:(WORequest *) aRequest inContext:
   (WOContext *) aContext;
- (WOElement *)invokeActionForRequest:(WORequest *) aRequest inContext:
   (WOContext *) aContext;
- (void)appendToResponse:(WOResponse *) aResponse inContext: 
   (WOContext *) aContext;

 

Details of these three methods can be found in the documentation of WODynamicElement.

See Also

Questions

Keywords

Revision History

22 July, 1998. Winnie Pun. First Draft.
19 November, 1998. Clif Liu. Second Draft.