Control
Remarks
Properties
ID_animators | A SitedList of animators. |
ID_controlId | The ID this control is known in the nearest binding container parent. |
ID_eventMask | (Advanced) A comma-separated list of peer events this control should receive. |
ID_isBindingContainer | (Advanced) Force this control to act as a binding container. |
ID_isPeerless | (Advanced) Set this to true to prevent this control from generating a peer element in the rendered HTML. |
ID_submitters | A SitedList of submitters. |
ID_tagName | Overrides the default HTML tag name used for this control. |
ID_visible | True if this control is visible, false if it is hidden. |
Events
ID_mouseDown | Event handler called when a mouse button is pressed down. |
ID_mouseMove | Event handler called when the mouse is moved. |
ID_mouseOut | Event handler called when a leaves a control. |
ID_mouseOver | Event handler called when a mouse moves over a control. |
ID_mouseUp | Event handler called when a mouse button is released. |
Methods
acceptsDrop | Called to determine if this control will accept a drop. |
addBinding | Adds a databinding between a property on this object and a binding path. |
addBindingEx | Extended entry point for adding a binding. |
addCalculatedBinding | Adds a calculated binding for a property. |
addClassName | Adds a CSS class to this controls "class" attribute |
addEventHandler (inherited from SitedObject) | Adds a delegate to be called when the specified eventId occurs on this object. |
animateEx | Animates a property to a value. |
blur | Tells this control's peer to relinquish keyboard focus. |
bubble | Bubbles a message up the control hierarchy - calls onBubbleEvent on this control and each of its parents. |
captureMouse | Register a control to receive mouse move/up events |
construct | Used to initialize a markup control. |
equals (inherited from SitedObject) | Tests if two objects are equal. |
fireEventHandler (inherited from SitedObject) | Invokes any user event handlers registered for a particular event using SitedObject.addEventHandler(). |
focus | Tells this control's peer to request keyboard focus. |
getBindingContainer | Gets this object's nearest enclosing binding container. |
getBindingStatus (inherited from SitedObject) | Provides debugging information on bindings for this object. |
getEventMask | Gets an object indicating which peer events this control is interested in. |
getParent | Gets the parent Control of this control. |
getPathValue (inherited from SitedObject) | Traverses a binding path and returns the value at the end of it. |
getPeer | Gets the peer DOM element associated with this control. |
getPeerForParent | Gets the peer element of this control that the parent control should use in DOM manipulations. |
getPropertyInfo (inherited from SitedObject) | Gets information on a property. |
getResource | Given the ID of a resource, returns the resource's value. |
getSite (inherited from SitedObject) | Gets this object's site. |
getTagName | Gets the HTML tag name this control will use for its peer element. |
getValue | (Override) Gets a property, style or attribute. |
getViewState | Retrieve any viewstate that has been saved for this control in a previous session. |
getViewStateId | Get a unique and consistent viewstateId for this control. |
invalidateLayout | Tells the layout system to redo layout. |
onBubbleEvent | Called to handle a bubbled event. |
onDragEvent | Called to handle a drag drop event.. |
onFirstRender | Called the first time a control is rendered. |
onPeerCreated | Called when a peer is created. |
onPeerEvent | Called to dispatch low level events that arise in the Dom. |
onSetValue (inherited from SitedObject) | Called by SitedObject.setValue() when a property value is set on this object. |
onSited (inherited from SitedObject) | Called when this object is sited. |
onSitedRoot | Called when a control is added to the main control tree. |
onUnsited (inherited from SitedObject) | Called when this object is about to lose its site. |
onUnsitedRoot | Called when a control is removed from the main control tree. |
onValueSited (inherited from SitedObject) | Called when an object is sited within this object. |
onValueUnsited (inherited from SitedObject) | Called when an object is about to be unsited in this. |
onViewStateChanged | Overridable. Controls implement this method to update their viewstate. |
reflectOnBoundValue | Gets runtime reflection information on an underlying bound object. |
removeClassName | Removes a CSS class from this controls "class" attribute |
removeEventHandler (inherited from SitedObject) | Remove an existing delegate from the list of delegates for the specified event. |
render | Places the Html representation of this control into the htmlBuilder. |
renderAttributes | Called by Control.render() to render attributes for this control. |
renderChildren | Places the Html markup for all the Control inside this control into the htmlBuilder. |
setBounds | Convenience method to set the left/top/width/height of an element. |
setInitialValues (inherited from SitedObject) | Sets multiple property values on an object (during initialization only) |
setPathValue (inherited from SitedObject) | Traverses a binding path and sets the value at the end of it. |
setValue | (Override) Sets a property, style or attribute. |
setViewState | Save viewstate that should persist across sessions. |
startAnimator | Starts an animation. |
startDragDrop | Start a drag drop operation. |
stopAnimator | Stops an animation. |
toString (inherited from SitedObject) | Returns a string representation of this object. |
Control acceptsDrop method
JavaScript
var boolVal = control.acceptsDrop(dragEventArgs)
Remarks
Returns
Overriden In
Control addBinding method
JavaScript
control.addBinding(propertyId,bindingPath)
Remarks
Example
Here's how to create a LabelControl and bind its text property:
var label = new LabelControl(); label.addBinding(ID_text, ['../', ID_data, ID_people, 0, ID_firstName]);
Control addBindingEx method
JavaScript
control.addBindingEx(property,bindingPath,convert,convertBack,instant,defaultText)
Remarks
Control addCalculatedBinding method
JavaScript
control.addCalculatedBinding(propertyId,bindingPaths,calculationFunction)
Remarks
Control addClassName method
JavaScript
control.addClassName(className)
Control animateEx method
JavaScript
control.animateEx(duration,propertyId,toValue,units,onComplete,onCancel)
Remarks
Example
Here's how to animate the CSS width of a control to 60 pixels over half a second:
control.animateEx(500, "$width", 60, "px");
Control blur method
JavaScript
control.blur()
Control bubble method
JavaScript
control.bubble(evtId,optionalEventArgs)
Remarks
Example
This bubbles an ID_selectItem event up the control hierarchy:
this.bubble(ID_selectItem);
When ListControl receives a ID_selectItem bubbled event, it looks at which child generated the event and selects the appropriate item associated with that child. Using bubbled events in this way means that the items within the list don't have to "know about" the containing ListControl.
See Also
Control captureMouse method
JavaScript
control.captureMouse()
Remarks
Control construct method
JavaScript
control.construct()
Remarks
Controls that are defined via subclassing in markup are instantiated by first executing their constructor, then calling the construct() method on them. This method is used to initialize the control's defaults. Just like a constructor, any base class implementations of construct() are called first (in superclass-to-subclass order), before construct() is called on the current class.
Note that optional arguments are passed in to the construct method, representing any #param values and Placeholder controls referenced within within the control's defaults. This is done to initialize the control's defaults in an efficient way.
For most controls, this method is generated by the compiler. A no-op method is provided at the root.
Control focus method
JavaScript
control.focus()
Control getBindingContainer method
JavaScript
var aControl = control.getBindingContainer()
Remarks
ID_isBindingContainer
set to true
.Returns
ID_isBindingContainer
property is true, or null
if there is no binging container.Control getEventMask method
JavaScript
var obj = control.getEventMask()
Remarks
This method inspects the event handlers registered with the control, and parses the Control.ID_eventMask property, and returns an associative array containing the eventIds of all the events the control wishes to receive.
For each event the control wishes to receive, the associative map has an entry whose key is the event ID and whose value is true.
For example, if the user registers for click events, then getEventMask() returns an object for which obj[ID_click] = true.
Returns
Overriden In
Control getParent method
JavaScript
var aControl = control.getParent()
Remarks
Returns null if this object is note added to a control hierarchy, or if it is a AppControl.
Note that this differs from the controls "site" (see SitedObject.getSite()).
A control's site is a SitedList, which
in turn sited as the "childControls" property of a control.
In otherwords, calling control.getParent()
is
equivalent to calling control.getSite().getSite()
.
Returns
Control getPeer method
JavaScript
var element = control.getPeer()
Remarks
Returns
Control getPeerForParent method
JavaScript
var element = control.getPeerForParent()
Remarks
Container controls always call this method to determine which element a child control is using.
The default implementation simply returns this.getPeer()
.
A few controls may additional hidden HTML elements above their peer in the DOM - if a control does this, it should override getPeerForParent to return the outermost element it added to the DOM, so that any DOM manipulations by the parent control (insertChild, appendChild etc.) continue to work.
Returns
See Also
Control getResource method
JavaScript
control.getResource(resourceId)
Remarks
This takes a resource Id, and returns the value of the resource. Currently, only string resources are supported.
If you create a control that defines a CSS resource cssTableClass, then use this.getResource(ID_cssTableClass) to get the value of the resource in code.
Control getTagName method
JavaScript
var strVal = control.getTagName()
Remarks
This method is called during rendering to get the name of the HTML tag to use for control's peer element.
Control's implementation method returns the value of the
ID_tagName
property if it is available, or "span" if no ID_tagName is set.
Subclasses may override this method to specify a different tag name. For example, ContainerControl returns "div" instead of "span" by default.
Returns
Overriden In
Control getValue method (override)
JavaScript
var obj = control.getValue(propertyId)
Remarks
Overrides SitedObject.getValue() to add support for getting styles and attributes.
Control's getValue
method uses the first letter of the specified propertyId
string
argument to decide what kind of value is being retrieved. If the first character is '@'
getValue retrieves the value of an HTML DOM attribute on this control's peer. If
the first character is '$', it returns the value of a CSS stylesheet style on
this control's peer. Otherwise,
propertyId must be an ID name declared using the IdManager, and the value
is retrieved from the control itself.
(To remember this, think "@" as in "@ttribute", and "$" as "$tyle").
N.B. This method is safe to call even if the control's peer has not yet been created, since controls retain an internal table of styles and attributes.
Returns
Example
To get the HTML "title" attribute of a control, use:
var title = control.getValue("@title"); alert("The control's title is: " + title);
To get the CSS "height" stylesheet property of a control, use:
var height = control.getValue("$height"); alert("The control's height is: " + height);
To get the controls ID_tagName property, use:
var tagName = control.getValue(ID_tagName); alert("The control's tagName is: " + tagName);
Base Implementation
See Also
Control getViewState method
JavaScript
control.getViewState()
Remarks
The viewstate will be in the form of a string, with its value being whatever the control previously saved with Control.setViewState().
Note: this method should be called only in a control's onFirstRender method, as this is both the time at which the data for the control has already been reestablished, and the time at which the control is fully sited within its root site.
Control getViewStateId method
JavaScript
control.getViewStateId()
Remarks
Control ID_animators property
JavaScript
var animatorList = control.getValue(ID_animators)
control.setValue(ID_animators, animatorList)
Xml
<j:Control>
<j:Animator ... />
<j:Animator ... />
...
</j:Control>
Remarks
Control ID_controlId property
JavaScript
var idname = control.getValue(ID_controlId)
control.setValue(ID_controlId, idname)
Xml
<j:Control controlId="string" ... >
Remarks
#bind(controls.xxx)
where xxx is the controlId you use.
Control ID_eventMask property (advanced)
JavaScript
var strVal = control.getValue(ID_eventMask)
control.setValue(ID_eventMask, strVal)
Xml
<j:Control eventMask="string" ... >
Remarks
You use ID_eventMask to extend which events on the control's peer are wired up to fire Control.onPeerEvent().
By default, only a restricted subset of HTML events on the peer element are setup to fire events in the control hierarchy. You can use eventMask to explicity extend this set of events.
In general, application writers do not need to worry about eventMask - when you add event handlers to a control it automatically sets the relevant flags in eventMask. Sometimes, however, control authors need to receive additional events from the HTML peer. Use eventMask to force the control to wire up events to fire onPeerEvent.
Example
To specify that a control should receive onkeydown and onkeyup events, use:
<MyControl eventMask="keyDown,keyUp" .../>
After doing this, MyControl's onPeerEvent method will be called with ID_keyDown and ID_keyUp events.
Control ID_isBindingContainer property (advanced)
JavaScript
var boolVal = control.getValue(ID_isBindingContainer)
control.setValue(ID_isBindingContainer, boolVal)
Xml
<j:Control isBindingContainer="true" ... >
or
<j:Control isBindingContainer="false" ... >
Remarks
Setting ID_isBindingContainer true causes this control to act as a binding container.
When resolving databindings, the binding engine starts with the control the binding is specified on, and searches upwards in the control hierarchy stopping at the first control it encounters whose ID_isBindingContainer property is true. It then traverses the binding path on that binding container.
Control authors typically specify ID_isBindingContainer on a class level - for example, AppControl sets the default for ID_isBindingContainer to true.
You can use the ID_isBindingContainer property lets you specify binding containers on a per-control level.
Control ID_isPeerless property (advanced)
JavaScript
var boolVal = control.getValue(ID_isPeerless)
control.setValue(ID_isPeerless, boolVal)
Xml
<j:Control isPeerless="true" ... >
or
<j:Control isPeerless="false" ... >
Remarks
Setting ID_isPeerless to true tells the Control.render() method to skip rendering the tag for this control - instead it only to renders the control's children.
Peerless controls are required in a few rare cases where a control must be present in the control hierarchy for databinding or behavior reasons, but where generating a peer HTML element for the control breaks the HTML or CSS - e.g. because of restrictions in HTML or because of the way the CSS stylesheets were authored.
N.B. Setting this to true breaks many controls.
Control ID_mouseDown event
JavaScript
control.addEventHandler(ID_mouseDown, new Delegate(obj, func))
Xml
<j:Control mouseDown="alert('mouseDown happened')" ... >
Example
In Xml, writing:
<j:Button mouseDown="alert('mouse down');" text="Foo"/>
creates a mouse Down event handler on the Button. When the mouse is pressed down on the button, an alert pops up saying 'mouse down'.
In JavaScript, you write:
// create a click function function myDown() { alert('Hello'); } // create a button var btn = new ButtonControl(); // register myDown as an event handler for the button btn.addEventHandler(ID_mouseDown, new Delegate(btn, myDown));
Control ID_mouseMove event
JavaScript
control.addEventHandler(ID_mouseMove, new Delegate(obj, func))
Xml
<j:Control mouseMove="alert('mouseMove happened')" ... >
See Also
Control ID_mouseOut event
JavaScript
control.addEventHandler(ID_mouseOut, new Delegate(obj, func))
Xml
<j:Control mouseOut="alert('mouseOut happened')" ... >
See Also
Control ID_mouseOver event
JavaScript
control.addEventHandler(ID_mouseOver, new Delegate(obj, func))
Xml
<j:Control mouseOver="alert('mouseOver happened')" ... >
See Also
Control ID_mouseUp event
JavaScript
control.addEventHandler(ID_mouseUp, new Delegate(obj, func))
Xml
<j:Control mouseUp="alert('mouseUp happened')" ... >
See Also
Control ID_submitters property
JavaScript
var submitterList = control.getValue(ID_submitters)
control.setValue(ID_submitters, submitterList)
Xml
<j:Control>
<j:Submitter ... />
<j:Submitter ... />
...
</j:Control>
Remarks
Control ID_tagName property
JavaScript
var strVal = control.getValue(ID_tagName)
control.setValue(ID_tagName, strVal)
Xml
<j:Control tagName="string" ... >
Remarks
In most cases, each control decides which HTML element to use to render the control, according to properties set on the control. For example, ButtonControl renders as either a "a", "link" or "input" element depending on the value of returned by ButtonControl.getButtonType().
In some cases, control users can override the default HTML tag name used by a control by setting the ID_tagName property.
The most general example is ElementControl, which simply outputs the value of ID_tagName property, enabling applications generate an arbitrary HTML element on the page.
N.B. Setting an ID_tagName property incorrectly will break the rendered HTML or cause the control to function strangely. For example, if you a set LabelControl's tagName property to "img", the label will cease showing the text. Similarly, if you set a control's tagName to "<", this will cause unexpected results.
See Also
Control ID_visible property
JavaScript
var boolVal = control.getValue(ID_visible)
control.setValue(ID_visible, boolVal)
Xml
<j:Control visible="true" ... >
or
<j:Control visible="false" ... >
Remarks
Setting ID_visible
to false
has the side effect of setting this control's
'visibility' style attribute is set to 'hidden'. Setting ID_visible
to true
has the side effect of setting this control's 'visibility'
style attribute to 'visible'.
This is simply a convenient way of setting the visibility
attribute of this control - its particularly
useful in databinding, since it saves you having to use a converter
to convert true
to 'visible' and false
to 'hidden'.
Control invalidateLayout method
JavaScript
control.invalidateLayout()
Remarks
Control onBubbleEvent method
JavaScript
var boolVal = control.onBubbleEvent(sender,bubbleEventArgs)
Remarks
This overridable method is called to handle bubble events.
Return false to stop this event from bubbling further up the control hierarchy, true if the event dispatching should continue.
Some bubble events may have a single optional argument object - see documentation for specific events.
If you override the method, be sure to call the base class's version.
The sender argument is the object that called Control.bubble().
The bubbleEventArgs is a JavaScript object with the following properties:
Property | Description |
eventId | The ID of the bubbled event, e.g. ID_selectItem, ID_nextCard, ID_previousCard. |
path | An array of sited objects that the bubble event has been sent to so far. The path[0] is the sender. path[path.length-1] is the object whose site is this object. |
Returns
Overriden In
See Also
Control onDragEvent method
JavaScript
control.onDragEvent(dragEventArgs)
Remarks
This overridable method is called to process drag drop events. Control's implementation does nothing. Subclasses override this method to add drag drop behavior.
The eventId is one of the following:
ID_dragBegin | The mouse moved after a startDragDrop was called - initiate a drag drop. |
ID_dragEnter | During a drag drop, the mouse entered the bounding
box of this control. Show feedback as appropriate. The control must have the property ID_isDropTarget set to true to receive this message. |
ID_dragLeave | During a drag drop, the mouse exited the bounding
box of this control. Stop showing feedback. The control must have the property ID_isDropTarget set to true to receive this message. |
ID_dragOver | The mouse moved while within this control, during a drag drop.
Show appropriate feedback. The control must have the property ID_isDropTarget set to true to receive this message. |
ID_dragEnd | The user let go of the mouse button - end the drag and drop interaction.
This is fired on the source control that initiated the drag drop. Control implementors should look at the dragEventArgs.targetControl - it this is null, the user let go of the mouse outside any drop target, so cancel the drag drop. If it is non-null, it is the target control the objects were dragged onto. This control (the source of the drag drop) should remove the dragged objects from its data model. |
ID_drop | The user dropped something on this control.
This is fired on the target control that receives the dropped objects, after ID_dragEnd is called on the source control that started the drag drop. Implementors should add the dropped objects to their data model. |
The dragEventArgs is a JavaScript object with the following properties:
eventId | Either ID_dragBegin, ID_dragEnter, ID_dragLeave, ID_dragOver, ID_dragEnd, ID_drop. |
dragElement | A temporary DOM element used for visual feedback during a drag operation. |
objects | The data objects that are being dragged. |
offsetX | The mouse offset X from the left of dragElement. |
offsetY | The mouse offset Y from the top of dragElement. |
sourceControl | The control that initiated the drag. |
targetControl | The current target control where a drop will occur. |
peerEvent | The XPlatformEvent for the mouse event that caused this message. |
Overriden In
Control onFirstRender method
JavaScript
control.onFirstRender()
Remarks
This overridable method is called the first time a contol is rendered. The default implementation does nothing.
If you override the method, be sure to call the base class's version.
Overriden In
Control onPeerCreated method
JavaScript
control.onPeerCreated()
Remarks
Control onPeerEvent method
JavaScript
var boolVal = control.onPeerEvent(eventId,eventArgs)
Remarks
This method is called whenever an event was generated by this controls peer element in the Dom. It examines the event and calls one of the corresponding onXXX methods, which in turn call fireEventHandler to notify listeners of events.
A side effect of this method is that ID_isMouseOver to true or false when the mouse moves in and out of the control. onPeerEvent It also fires ID_mouseOver, ID_mouseOut, ID_mouseDown, ID_mouseUp and ID_mouseMove user event handlers, by calling SitedObject.fireEventHandler().
Returns
Overriden In
Control onSitedRoot method
JavaScript
control.onSitedRoot()
Remarks
This overridable method is called when the control is added to the main control hierarchy.
If you override the method, be sure to call the base class's version.
Control onUnsitedRoot method
JavaScript
control.onUnsitedRoot()
Remarks
This overridable method is called when the control is removed from the main control hierarchy.
If you override the method, be sure to call the base class's version.
Control onViewStateChanged method
JavaScript
control.onViewStateChanged()
Remarks
Control reflectOnBoundValue method
JavaScript
var propertyInfo = control.reflectOnBoundValue(propertyId)
Remarks
Returns
Example
The following code inspects the object bound to the ID_text property of a control, and prints its displayName if it exists.
var propertyInfo = obj.reflectOnBoundValue(ID_apply); if (propertyInfo != null) Diagnostics.write(propertyInfo.getValue(ID_displayName));
Control removeClassName method
JavaScript
control.removeClassName(className)
Control render method
JavaScript
control.render(htmlBuilder)
Remarks
Calling this appends this control's Html markup to the HtmlBuilder's buffer. The generated markup includes Html for the control's peer element and for all the childControls of the control.
This method is used when a control becomes live for the first time, to generate the Html version of the the control to insert in the document.
Subsequently, changes to the control are pushed out to the Html document via direct manipulation of the control's peer element (see Control.getPeer()), or by calling Control.renderChildren() and setting that as the innerHTML of the peer.
Example
The following code obtains a string Html representation of the default app on a page:
var htmlBuilder = new HtmlBuilder(); document.apps[0].render(htmlBuilder); alert('The html is' + htmlBuilder.toString());
Control renderAttributes method
JavaScript
control.renderAttributes(htmlBuilder)
Remarks
This method uses HtmlBuilder.addAttribute() or HtmlBuilder.addEventAttribute() to add any attributes required by the current control. Control's default implementation outputs an id for the peer, a "cidp" attribute (control id path - an internal attribute used to track this peer), and any user-specified attributes or styles set with Control.setValue().
Subclasses may override this method and add additional control-specific attributes. If you override this method in a control, be sure to call the base-class version.
Overriden In
Control renderChildren method
JavaScript
control.renderChildren(htmlBuilder)
Remarks
This method is called by ContainerControl.render().
Control's default implementation of renderChildren does nothing. Subclasses (e.g. ContainerControl.renderChildren()) override this method to append the inner markup for the control in the htmlBuilder.
Notice that this method does not generate the markup for the control's peer element - that markup is generated automatically by render.
Example
The following code refreshes the Html contents of a control:
var htmlBuilder = new HtmlBuilder(); control.renderChildren(htmlBuilder); control.getPeer().innerHTML = htmlBuilder.toString();
Overriden In
Control setBounds method
JavaScript
control.setBounds(bleft,btop,bwidth,bheight,border)
Remarks
Control setValue method (override)
JavaScript
control.setValue(propertyId,newVal)
Remarks
Overrides SitedObject.setValue() to add support for styles and attributes.
Control's setValue
method uses the first letter of the
specified propertyId
string argument to decide what kind of value is being set.
If the first character is '@', setValue sets the value of an HTML DOM attribute
on this control's peer. If the first character is '$', setValue sets the value
of a CSS stylesheet style on this control's peer. Otherwise,
propertyId must be an ID name declared using the IdManager, and the value
is set on the control itself.
(To remember this, think "@" as in "@ttribute", and "$" as "$tyle").
N.B. This method is safe to call even if the control's peer has not yet been created, since controls retain an internal table of styles and attributes.
Example
To set the HTML "title" attribute of a control, use:
control.setValue("@title", 'Hello World');
To set the CSS "left" stylesheet property of a control, use:
control.setValue("$left", '10px');
To set the ID_text property of a button control, use:
button.setValue(ID_text, "Here is the text" );
Base Implementation
See Also
Control setViewState method
JavaScript
control.setViewState(state)
Remarks
Control startAnimator method
JavaScript
control.startAnimator(animatorId)
Remarks
This method searches for an animator with the specified animatorId. If the animator is found, a new animation is scheduled on this control using the matching animator. If no animator is found, this does nothing.
Notice that you can create a single animator and then reuse it on several controls at once. Each time you call startAnimator it launches an independent animation.
Control startDragDrop method
JavaScript
control.startDragDrop(objects,existingElement,dragElement,mouseEventArgs)
Control stopAnimator method
JavaScript
control.stopAnimator(animatorId)