IBM BPM, V8.0.1, All platforms > Create processes in IBM Process Designer > Create user interfaces for business processes > Coach and Coach View reference information

The context object

The Coach View context object provides access to helper functions, for example a callback to fire a named boundary event.


context.containDiffLoopingContext()

Returns true if all of the following conditions are true:

For example, the API returns true for the following structure when ListA has four items and ListB has three items.

TableView (bind to ListA[])
	ContentBox
		TextView (bind to ListB.currentItem)

The framework displays a message at run time when there is a mismatch in list lengths. See Data binding for Coach Views.

For example, a table calls containDiffLoopingContext() to determine if it needs to disable its add and delete capability during the runtime even if a user has specified to enable add and delete capability.

If the Coach View that contains a content box is bound to a list that is not empty and the content box is view-managed, do not call this API between deleting a DOM node of the content box and rendering of the first repeating element. The return value might not be accurate.


context.createView(domNode, index, parentView)

Calls the framework to create a view instance and any subview instances starting from the specified domNode, which is usually the contextBox div.

If domNode is the node of any view other than a contentBox, a single instance of the view is created and returned.

If domNode is the node of a contextBox, the framework creates view instances for all the views that are owned by the contentBox, and recursively creates views for all the framework managed contentBoxes that are owned by this contentBox. An array of view instances is returned.

The following code snippet shows how to create a content box view.

var location = 5;
// rowTemplate is the contentBox that contains some nodes // the view nodes define table columns.
trElement.appendChild(oneDiv);
this.tableElement.appendChild(trElement);

For
more information, see  Example: Get and use a domNode.





context.deleteView(domNode)

Calls the framework to delete the view instance and any subview instances starting from the specified domNode.

  • domNode - the ContentBox node or the node of any view

The following code snippet shows how to delete a view instance:

var nodeToDelete = document.getElementById("myId");
this.context.deleteView(nodeToDelete);
nodeToDelete.parentNode.removeChild(nodeToDelete);
For more information, see Example: Get and use a domNode.


context.element

Contains the root DOM element of the view. The view must not delete this DOM element. Content views that are defined in the layout are children of this root element. Generally, the view uses this root DOM element to locate its own content.

Multiple instances of the same view can be on the same HTML page, use this root DOM element to scope your search.


context.getInheritedVisibility()

Called by the view instance to obtain the ancestor's visibility setting value.

If all the ancestors' visibility values are set to "default", the function returns EDITABLE.


context.getSubview(viewId, requiredOrder)

Accesses a subview instance given the subview ID. This method is similar to context.subview[viewid] except that the return value is an array of subview instances.

  • viewId(String) - the view ID or control ID of the subview
  • requiredOrder (boolean) - (optional) indicates whether the array returned needs to maintain the same order as in the DOM tree. The default value is false.

The call this.context.getSubview("viewid") returns an unsorted array of subview objects. The call this.context.getSubview("viewid", false) returns exactly same array. The only difference between the two calls and the function call this.context.getSubview("viewid", true) is that this.context.getSubview("viewid", true) returns an array of subview objects whose order matches the order of the DOM nodes in the DOM tree. See Access a child Coach View.


context.htmlEscape(text)

Escapes the specified text. This function is used to avoid potential cross-site scripting (XSS) attacks.

text(String) - the text to escape. The escaped text is returned


context.parentView()

Returns the parent view instance or null if there is no parent view. During the invocation of load(), the parentview object is created but not fully initialized (one reason is that the parent view's load() is called after the current load() ), therefore, avoid calling this function in the load() function.


context.refreshView()

Forces the view and all its subviews to rebind. As a result, the change() callback is called, which causes the view (and all its subviews) to refresh.


context.setDisplay(isDisplay, domNode)

Shows or hides the specified domNode. The specified domNode has a CSS class that is added or removed which sets the "display:none"

  • isDisplay (boolean): true to show; false to hide
  • domNode (DOMElement): optional parameter.

    If not specified, the root element of the current view is used.

See Example: Get and use a domNode.


context.subscribeValidation()

Registers the Coach View to receive the validation errors of descendant Coach Views that are bound to a different business object than the current Coach View. These errors are contained in the errors_subscription list of the error event object. Coach Views that do not have a data binding, such as the Tab stock control, can use this API to receive validation errors.


context.subview[viewid]

Returns an object with the div ID of the subview as a property name. In a non-repeating scenario, there should be only one property. Generally context.getSubview() is a more convenient function to use.

viewid (String): the view ID or control ID. See Example: Get and use a domNode and Example: Get a div ID.


context.trigger(callback)

Fires a named boundary event. When the boundary event is handled, the supplied callback is called. The callback function is optional.

There is no parameter for the callback function.


context.triggerCollaboration(payload)

Fires a custom collaboration event. The custom message is sent to the browser of a collaborating user. The corresponding view on the collaborating browser receives the collaboration() callback with event.type = "custom".

payload(String) = custom message


context.unsubscribeValidation()

Unregisters the Coach View so that it no longer receives errors in the errors_subscription list. The Coach View still receives the errors list if it exists.


context.viewid

Contains the unique identifier for this view definition. Multiple view instances might have the same viewId. See context.getSubview(viewId, requiredOrder).


Example: Get and use a domNode

Many functions of the context object take a document node (domNode) as an argument. The following code example shows how to get a domNode and use it in a function.

 1  var subview = this.context.getSubview("subviewID", "true")[5];
 2  var subviewDomNode = subview.context.element;
 3  this.context.deleteView(subviewDomNode);  

  •  1  The parameter subviewID is the control ID of the subview and corresponds to the value for the attribute data-viewid of the <div></<div> tag of the subview instance. The function getSubview(subViewID) returns an array of subviews. In our example, we want the sixth element in the index of arrays. The parameter true ensures that the objects of the array are returned in the same order as the DOM.
  •  2  Get the domNode of the subview element that is returned in step 1.
  •  3  Delete the subview by using the domNode that step 2 returns.


Example: Get a div ID

To get the div ID of an element, use the syntax this.context.element.id

To get the ID of a subview, first get the domNode of the subview and then use .id.

 1  var subview = this.context.getSubview("subviewID", "true")[5];
 2  var subviewDomNode = subview.context.element;
 3  var subViewDomId = subviewDomNode.id; // This gives you the id of the subview

  •  1  The parameter subviewID is the control ID of the subview and corresponds to the value for the attribute data-viewid of the <div></<div> tag of the subview instance. The function getSubview(subViewID) returns an array of subviews. In our example, we want the sixth element in the index of arrays. The parameter true ensures that the objects of the array are returned in the same order as the DOM.
  •  2  Get the domNode of the subview element that is returned in step 1.
  •  3  Get the ID of the subview.

  • Predefined data
    The context provides read access to a predefined set of data.
  • Binding data and configuration options
    A Coach view may be associated with a data binding and configuration options. The view context provides access to this data. To access binding data and configuration options use the JavaScript get and set functions. You cannot use JavaScript dot notation.

Coach and Coach View reference information


Related concepts:
Boundary events


Related tasks:
Access a child Coach View


Related reference:
The view object
Event handlers
Predefined data
Binding data and configuration options