SitedObject

Base class for all objects that support change notification and sites.

Remarks

A sited object is a JavaScript object that has a site (a containing parent) and sends change notification messages.

Methods

addEventHandlerAdds a delegate to be called when the specified eventId occurs on this object.
equalsTests if two objects are equal.
fireEventHandlerInvokes any user event handlers registered for a particular event using SitedObject.addEventHandler().
getBindingStatusProvides debugging information on bindings for this object.
getPathValueTraverses a binding path and returns the value at the end of it.
getPropertyInfoGets information on a property.
getSiteGets this object's site.
getValueGets the value of a property on this object.
onSetValueCalled by SitedObject.setValue() when a property value is set on this object.
onSitedCalled when this object is sited.
onUnsitedCalled when this object is about to lose its site.
onValueSitedCalled when an object is sited within this object.
onValueUnsitedCalled when an object is about to be unsited in this.
removeEventHandlerRemove an existing delegate from the list of delegates for the specified event.
setInitialValuesSets multiple property values on an object (during initialization only)
setPathValueTraverses a binding path and sets the value at the end of it.
setValueSets the value of a property on this object.
toStringReturns a string representation of this object.

SitedObject addEventHandler method

Adds a delegate to be called when the specified eventId occurs on this object.

JavaScript

sitedObject.addEventHandler(eventId,delegate)

Example

Here's how to add a click event handler to a button to call the global function myFunction:

function myFunction() { alert('Called'); }

var b = new ButtonControl();
b.addEventHandler(ID_click, new Delegate(null, myFunction));

See Also

SitedObject equals method

Tests if two objects are equal.

JavaScript

var boolVal = sitedObject.equals(otherObj)

Remarks

This overridable method lets classes specify an alternative equals routine for comparing objects. This method is called by SitedList and SitedObjectReference among others.

Returns

true if this object and otherObj are equal, false otherwise.

SitedObject fireEventHandler method

Invokes any user event handlers registered for a particular event using SitedObject.addEventHandler().

JavaScript

var boolVal = sitedObject.fireEventHandler(eventId,eventArgs)

Remarks

This method looks for any user handlers that are registered with this eventId, and executes them, passing them the delegate two arguments: this sender object, and the eventArgs object.

Returns

false if any event handler was called, and true if no event handler was called and dispatching should continue to look for an event handler.

SitedObject getBindingStatus method

Provides debugging information on bindings for this object.

JavaScript

sitedObject.getBindingStatus()

Remarks

Returns 0 if this object has no bindings. Returns 1 if this object has bindings and they are all connected and have non-null values. Returns -1 if this object has a binding which is unconnected to a source object. Returns -2 if this object has a binding which is connected to a source object but where the value of the bound property is undefined.

SitedObject getPathValue method

Traverses a binding path and returns the value at the end of it.

JavaScript

var obj = sitedObject.getPathValue(bindingPath)

Remarks

This takes a binding path specified as an array. It traverses the binding path and returns the value at the end of the path, or null if the binding fails.

This is the method called by all #bind() expressions.

The path argument must be an array containing the following element types:

Path ElementDescription
"../"Traverses to the next outer enclosing BindingContainerControl. Must occur at the start of the path. You can use '../','../', to skip up two binding containers. If the path does not start with '../' or '//', then the system will look in this object for the value of the binding.
"//"Traverses directly to the root binding container (the AppControl for the page).
stringMoves to the specified property name. e.g. if the string is ID_foo this traverses to the property ID_foo in the current object. property of the current object. If the current object does not have the property, the traversal fails.
numberMoves to the array index in the current list. e.g. if the number is 3 this traverses to the third element in the current data list. If the current object is not a DataList, the traversal fails.

Returns

The value at the end of the path, or null if the path fails to resolve.

Example

When you write a binding expression like <onClick="alert(#bind(person.firstName))", this is compiled into something like:

alert(this.getPathValue([ '../', 'person', 'firstName' ]));

(Since creating arrays dynamically is slow, the page compiler generates all path arrays as global variables which it reuses, so the actual code you see in a page will be more like:

// shared paths at the top of the page
var sp.b1 = [ '../', 'person', 'firstName' ];

	...
	alert(this.getPathValue(sp.b1));
	...

SitedObject getPropertyInfo method

Gets information on a property.

JavaScript

var propertyInfo = sitedObject.getPropertyInfo(propertyId)

Remarks

This returns a PropertyInfo holding runtime reflection metadata for a given property key on this object, or null if the property has no special metadata.

Returns

An object containing reflection metadata, or null if there is no metadata available on the specified propertyId.

Example

The following code prints the displayName of the ID_firstName property on an object, if it exists.

var pinfo = obj.getPropertyInfo(ID_firstName);
if (pinfo != null)
	Diagnostics.write(pinfo.getValue(ID_displayName));

SitedObject getSite method

Gets this object's site.

JavaScript

var aSitedObject = sitedObject.getSite()

Remarks

An object may be sited in two ways: Either it is set as a property value in another SitedObject (in which case the site is the parent object), or it is added to a SitedList (in which case the site is the SitedList).

Returns

This object's site, or null if this object is unsited.

Example

In this example we create a SitedObject obj, make another SitedObject s1, and then set s1 as the value of ID_someProperty on obj:

var obj = new SitedObject();
var s1 = new SitedObject();
obj.setValue(ID_someProperty, s1);
// Now s1.getSite() == obj

In this next example, we add a SitedObject to a list:

var list = new SitedList();
var s2 = new SitedObject();
list.add(s2);
// Now s2.getSite() == list

SitedObject getValue method

Gets the value of a property on this object.

JavaScript

var obj = sitedObject.getValue(propertyId)

Remarks

Call this method rather than dotting into an object using the object.propertyName convention, since the object may need to do additional work to retrieve the value.

Avoid using string literals as property IDs (object.getValue('foo')), since this won't work if you compile your application with the cruncher.

Returns

The value of the property specified by propertyId, or null if the property is not defined.

Example

Here's how to make the text property of a control uppercase.

function makeTextUpperCase(control) {
   var text = control.getValue(ID_text);
   control.setValue(ID_text, text.toUpperCase());
}

Overriden In

SitedObject onSetValue method

Called by SitedObject.setValue() when a property value is set on this object.

JavaScript

sitedObject.onSetValue(propertyId,oldVal,newVal,notificationSource)

Remarks

This overridable method is called any time someone calls setValue on this object to change the object's properties. Subclasses override this to respond to changes in properties as appropriate.

If you override the method, be sure to call the base class's version.

Overriden In

SitedObject onSited method

Called when this object is sited.

JavaScript

sitedObject.onSited()

Remarks

This overridable method is called when this object becomes sited, i.e. when this object gets a parent site. The SitedObject version does nothing.

SitedObject onUnsited method

Called when this object is about to lose its site.

JavaScript

sitedObject.onUnsited()

Remarks

This overridable method is called when this object is about to lose its site, i.e. when this object gets removed from its "parent" site. The default version does nothing.

If you override the method, be sure to call the base class's version.

SitedObject onValueSited method

Called when an object is sited within this object.

JavaScript

sitedObject.onValueSited(propertyId,sitedObject)

Remarks

This overridable method is called when an object is sited in this. i.e. when this object becomes the ID_parent of another sited object. The default version does nothing.

If you override the method, be sure to call the base class's version.

Overriden In

SitedObject onValueUnsited method

Called when an object is about to be unsited in this.

JavaScript

sitedObject.onValueUnsited(propertyId,sitedObject)

Remarks

This overridable method is called when an object is about to be unsited from this object, i.e. when this object is about to stop being the ID_parent of another sited object. The default version does nothing.

If you override the method, be sure to call the base class's version.

Overriden In

SitedObject removeEventHandler method

Remove an existing delegate from the list of delegates for the specified event.

JavaScript

sitedObject.removeEventHandler(eventId,delegate)

Remarks

If no matching eventHandler exists, do nothing.

SitedObject setInitialValues method

Sets multiple property values on an object (during initialization only)

JavaScript

sitedObject.setInitialValues()

Remarks

This method is used to efficiently set multiple property values on an object just after the object has been created and before it becomes live. This is a faster but less safe version of setValue. In this version, change notification is turned off. Also, if the object has any old property values, those old values will not be unsited by this call. setInitialValues should therefore only be used on newly created objects.

Example

Here is an example from the basic_button.html quick tour - this code was generated by the page compiler:

function initializeApp0(target, resourceOwner, data) {
	var o;

	// Create <Button> (line: 9)
	o = new ButtonControl();
	o.addEventHandler("click", new Delegate(target, line9_Button_click));
	o.setInitialValues(
		"text", 'Hello World');

	target.setInitialValues(
		"childControls", new SitedList(o));
};

SitedObject setPathValue method

Traverses a binding path and sets the value at the end of it.

JavaScript

sitedObject.setPathValue(bindingPath,val)

Remarks

This takes a binding path specified as an array. It traverses the binding path. If the traversal succeeds, this sets the value at the end of the path to the specified value.

Example

When you write a binding expression like <onClick="#bind(person.age) = 12;", this is compiled into something like:

this.setPathValue([ '../', 'person', 'firstName' ], 12);

SitedObject setValue method

Sets the value of a property on this object.

JavaScript

sitedObject.setValue(propertyId,newVal)

Remarks

Call this method rather than dotting into an object using the object.propertyName = value convention, since setting the value may have side effects (e.g. causing the DOM to get re-rendered).

Also, avoid using string literals for property keys (object.setValue('foo', 12)), since this won't work if you compile your application with the cruncher. Always use the property ID.

Example

Here's how to make the text property of a control uppercase.

function makeTextUpperCase(control) {
   var text = control.getValue(ID_text);
   control.setValue(ID_text, text.toUpperCase());
}

Overriden In

SitedObject toString method

Returns a string representation of this object.

JavaScript

var strVal = sitedObject.toString()

Remarks

This implementation overrides Object.toString to generate a string representation of this object containing the name of this object's type.

Returns

This object's type name as a string.