Behavior

An abstract class used in implementing Mojo Behaviors.  A Behavior is an object that encapsulates functionality for controlling and manipulating UI interaction/reaction.

Example

dojo.provide("sample.behavior.ClearFormBehavior");
dojo.require("mojo.command.Behavior");

dojo.declare("sample.behavior.ClearFormBehavior", mojo.command.Behavior,
function() {
},{
execute: function(requestObj) {
var inputs = mojo.query("input", this.getRequest().getContextElement());
for (var i = 0, len = inputs.length; i < len; i++) {
inputs[i].value = "";
}
}
});
Summary
An abstract class used in implementing Mojo Behaviors.
Returns the mojo.controller.Request object passed into the Behavior.
Abstract function that must be implemented in a concrete Behavior class.

Functions

getRequest

getRequest: function()

Returns the mojo.controller.Request object passed into the Behavior.

Returns

{object} Mojo Request Object

execute

execute: function(requestObj)

Abstract function that must be implemented in a concrete Behavior class.  The Controller will automatically fire the execute() method when triggering a Behavior.

Parameters

requestObj{object}

Example

dojo.declare("myapplication.command.toggleComponent", mojo.command.Behavior,
{
execute: function(requestObj) {

//In the UI, we have an anchor with the following markup--please note the *rel* attribute.
//<a id='component1' rel='component1Content' href='view/component1'>
//<div id='component1Content'>Lots of content goes here.</div>

var targetEl = mojo.queryFirst("#" + requestObj.callerObj.getAttribute('rel')); //CSS selector for the ID

//Now we have the reference to the content panel, so we can determine its state and toggle it accordingly.
if(targetEl.style.display == 'none') {
//Show it.
} else {
//Hide it.
}
}
});
getRequest: function()
Returns the mojo.controller.Request object passed into the Behavior.
execute: function(requestObj)
Abstract function that must be implemented in a concrete Behavior class.