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


Table of Contents Previous Section

Disabling Component Synchronization

Component synchronization can sometimes lead to values being set when you don't want them to be set. You have no control over when, or how often a value is passed to and from the parent.

For these reasons, component synchronization can be disabled. When components are not synchronized, they behave more like dynamic elements in that a value is not resolved with the parent component's settings until that value is needed.

To disable component synchronization, override the method synchronizesVariablesWithBindings in the reusable component's code file to return NO or false.

With component synchronization disabled, you must get values from the parent and set values in the parent yourself. The method valueForBinding: gets a value from the parent, and the method setValue:forBinding: (setValueForBinding in Java) set a value in the parent. The argument that you pass to these methods is the name of one of the reusable component's attributes.

For example, consider a reusable component named NonSyncComponent that you declare in a parent component in this way:

//parent component's .wod file
Childcomponent : NonSyncComponent {
stringValue = @"I'm a string!";
}
Suppose NonSyncComponent contains a WOTextField element that it declares in this way:

// NonSyncComponent.wod 
MyString : WOTextField {
value = someStringValue;
}
If NonSyncComponent's script file looks like the following, the value that the parent bound to the stringValue attribute is resolved with WOString's value attribute whenever WOString requests its value attribute. Thus, the WOString in this NonSyncComponent displays "I'm a string!"

// NonSyncComponent.wos
- synchronizesVariablesWithBindings {
return NO;
}

- someStringValue {
return [self valueForBinding:@"stringValue"];
}

- setSomeStringValue:aValue {
[self setValue:aValue forBinding:@"stringValue"];
}
If NonSyncComponent has no other need for someStringValue than to resolve the value attribute for its WOString, then NonSyncComponent can instead use this shorthand notation in its declarations file:

// Alternate NonSyncComponent.wod 
MyString : WOString {
value = ^stringValue;
}
The carat (^) syntax means "use the value that my parent bound to my stringValue attribute." This syntax is a convenience that saves you from having to always write cover methods for valueForBinding: and setValue:forBinding:. In addition to being more convenient, this syntax is often more efficient because none of your code is invoked to do either the pushing or the pulling.

Table of Contents Next Section