SitedObject
Remarks
Methods
addEventHandler | Adds a delegate to be called when the specified eventId occurs on this object. |
equals | Tests if two objects are equal. |
fireEventHandler | Invokes any user event handlers registered for a particular event using SitedObject.addEventHandler(). |
getBindingStatus | Provides debugging information on bindings for this object. |
getPathValue | Traverses a binding path and returns the value at the end of it. |
getPropertyInfo | Gets information on a property. |
getSite | Gets this object's site. |
getValue | Gets the value of a property on this object. |
onSetValue | Called by SitedObject.setValue() when a property value is set on this object. |
onSited | Called when this object is sited. |
onUnsited | Called when this object is about to lose its site. |
onValueSited | Called when an object is sited within this object. |
onValueUnsited | Called when an object is about to be unsited in this. |
removeEventHandler | Remove an existing delegate from the list of delegates for the specified event. |
setInitialValues | Sets multiple property values on an object (during initialization only) |
setPathValue | Traverses a binding path and sets the value at the end of it. |
setValue | Sets the value of a property on this object. |
toString | Returns a string representation of this object. |
SitedObject addEventHandler method
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
JavaScript
var boolVal = sitedObject.equals(otherObj)
Remarks
Returns
SitedObject fireEventHandler method
JavaScript
var boolVal = sitedObject.fireEventHandler(eventId,eventArgs)
Remarks
Returns
SitedObject getBindingStatus method
JavaScript
sitedObject.getBindingStatus()
Remarks
SitedObject getPathValue method
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 Element | Description |
"../" | 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). |
string | Moves 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. |
number | Moves 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
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
JavaScript
var propertyInfo = sitedObject.getPropertyInfo(propertyId)
Remarks
Returns
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
JavaScript
var aSitedObject = sitedObject.getSite()
Remarks
Returns
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
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
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
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
JavaScript
sitedObject.onSited()
Remarks
SitedObject onUnsited method
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
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
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
JavaScript
sitedObject.removeEventHandler(eventId,delegate)
Remarks
SitedObject setInitialValues method
JavaScript
sitedObject.setInitialValues()
Remarks
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
JavaScript
sitedObject.setPathValue(bindingPath,val)
Remarks
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
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
JavaScript
var strVal = sitedObject.toString()