Zimlet JavaScript API Reference - DwtMessageComposite

Class DwtMessageComposite


Extends DwtComposite.

This class allows you to create a composite that is populated from a message pattern and inserts controls at the appropriate places. For example, say that the message MyMsg.repeatTimes is defined as the following:

MyMsg.repeatTimes = "Repeat: {0} times";
and you want to replace "{0}" with an input field or perhaps a drop-down menu that enumerates a specific list of choices as part of the application. To do this, you just create a DwtMessageComposite and set the message format, like so:
var comp = new DwtMessageComposite(parent);
comp.setFormat(MyMsg.repeatTimes);

The message composite instantiates an AjxMessageFormat from the specified message pattern. Then, for each segment it creates static text or a DwtInputField for replacement segments such as "{0}".

To have more control over the controls that are created and inserted into the resulting composite, you can pass a callback object to the method. Each time that a replacement segment is found in the message pattern, the callback is called with the following parameters:

  • a reference to this message composite object;
  • a reference to the segment object.
  • the index at which the segment was found in the message pattern; and
The segment object will be an instance of AjxMessageFormat.MessageSegment and has the following methods of interest:
  • toSubPattern
  • getIndex
  • getType
  • getStyle
  • getSegmentFormat

The callback can use this information to determine whether or not a custom control should be created for the segment. If the callback returns null, a standard DwtInputField is created and inserted. Note: if the callback returns a custom control, it must be an instance of AjxControl.

Here is an example of a message composite created with a callback that generates a custom control for each replacement segment:

function createCustomControl(parent, segment, i) {
    return new DwtInputField(parent);
}

var compParent = ...;
var comp = new DwtMessageComposite(compParent);

var message = MyMsg.repeatTimes;
var callback = new AjxCallback(null, createCustomControl);
comp.setFormat(message, callback);


Defined in: DwtMessageComposite.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
DwtMessageComposite(params, parent, className, posStyle, parent, format, controlCallback, hintsCallback)
Creates a composite that is populated from a message pattern.
Method Summary
Method Attributes Method Name and Description
 
Gets the format.
 
setFormat(message, callback, hintsCallback)
Sets the format.
Methods borrowed from class DwtComposite:
addChild, cleanupSeparators, clear, dispose, getChild, getChildren, getNumChildren, getTabGroupMember, removeChild, removeChildren
Methods borrowed from class DwtControl:
addClassName, addControlListener, addDisposeListener, addListener, appendElement, blur, clearContent, clearHandler, condClassName, delClassName, focus, getBounds, getClassName, getContent, getCursor, getData, getDragBox, getDragSource, getDropTarget, getEnabled, getFocusElement, getH, getHtmlElement, getHTMLElId, getInsetBounds, getInsets, getLocation, getMargins, getOpacity, getOuterSize, getPosition, getScrollContainer, getScrollStyle, getSize, getTooltipBase, getToolTipContent, getVisibility, getVisible, getW, getX, getXW, getY, getYH, getZIndex, hasFocus, isAlertShown, isDisposed, isInitialized, isListenerRegistered, notifyListeners, preventContextMenu, preventSelection, removeAllListeners, removeControlListener, removeDisposeListener, removeListener, reparent, reparentHtmlElement, replaceElement, setBounds, setClassName, setContent, setCursor, setData, setDisplay, setDisplayState, setDragBox, setDragSource, setDropTarget, setEnabled, setEventPropagation, setFocusElement, setHandler, setHtmlElementId, setLocation, setOpacity, setPosition, setScrollStyle, setSize, setToolTipContent, setVisibility, setVisible, setZIndex, showAlert, zShow
Class Detail
DwtMessageComposite(params, parent, className, posStyle, parent, format, controlCallback, hintsCallback)
Creates a composite that is populated from a message pattern.
Author: Andy Clark.
Parameters:
{Object} params
hash of params:
{DwtComposite} parent
the parent widget.
{string} className
the CSS class
{constant} posStyle
the position style (see DwtControl)
{DwtComposite} parent
the parent widget.
{string} format
the message that defines the text and controls within this composite control
{AjxCallback} controlCallback Optional
the callback to create UI components (only used with format specified)
{AjxCallback} hintsCallback Optional
the callback to provide display hints for the container element of the UI component (only used with format specified)
Method Detail
{string} format()
Gets the format.
Returns:
{string} the format

setFormat(message, callback, hintsCallback)
Sets the format.
Parameters:
{string} message
the message that defines the text and controls that comprise this composite
{AjxCallback} callback Optional
the callback to create UI components
{AjxCallback} hintsCallback Optional
the callback to provide display hints for the container element of the UI component

Documentation generated by JsDoc Toolkit 2.3.0 on Tue Jun 28 2016 21:01:29 GMT-0400 (EDT)