Designing and Implementing Composite Applications : webMethods CAF and OpenCAF Development Help : Understanding the Client-side Model : CAF.Tree.Model
CAF.Tree.Model
The CAF.Tree.Model extends the CAF.Table.Model, adding methods for expanding and collapsing tree rows. You can expand or collapse individual rows using collapse(value), expand(value), or toggle(value), with their server-side row-ID (the value arg). Use the getRoots() method to retrieve the CAF.Tree.Row.Model roots.
You can determine the state of the tree rows using methods on the CAF.Tree.Row.Model that extend the CAF.Table.Row.Model. The getParent() method of the CAF.Tree.Row.Model returns the CAF.Tree.Row.Model for the parent of the row. The getChildren() method returns the array of CAF.Tree.Row.Model children. The isOpen() method returns true if the row is expanded and false if collapsed. The setOpen(open) method expands or collapses the row. Unlike other CAF.Select.Item.Model and CAF.Table.Row.Model methods, the setOpen () method takes effect immediately, rather than when the container model's set() method is invoked with the changed model.
Add or remove roots from the tree using the CAF.Select.Model's add() and remove() methods. You can add or remove rows using the addChild() and removeChild() methods of a row's CAF.Table.Row.Model. The CAF.Select.Item.Model and CAF.Table.Row.Model methods, addChild() and removeChild() take effect immediately rather than when the container model's set() method is invoked with the changed model.
A row template on a tree works the same as with the table. In the following example, if the tree can template rows, and it contains a dropdown with an ID of myDropdownId and a output text control with an ID of myOutputId, the following script would append a new row with a row-ID of my-new-row to the very last node in the tree, and set the row's dropdown to the "value-new" item and the row's output text to display My New Row:
var tree = CAF.model(treeId);
var node = tree.getRoots().last();
while (node && node.getHasChildren()) node = node.getChildren().last();
node.addChild(new CAF.Tree.Row.Model("my-new-row", { myDropdownId: "value-new",
myOutputId: "My New Row" });
With an async tree, not all rows are present on the client. If a row has children, but its children are not yet on the client, the CAF.Tree.Row.Model returns true for getHasChildren(), but an empty array for getChildren(). Use the CAF.Tree.Row.Model's isLoaded() method as a shortcut to test for this state. The isLoaded() method returns false if the row has children but the children are not on the client. To force the tree to request the children from the server, invoke setOpen(true) on the CAF.Tree.Row.Model, or invoke expand(value) on the CAF.Tree.Model.
Trees raise expand-all and collapse-all table-change events when the tree's expand-all and collapse-all state is modified. They raise toggle row-change events when individual rows are toggled expanded or collapsed. The async tree raises loaded row-change events when the children of a row are loaded.
For more information about CAF controls, see the webMethods CAF Tag Library Reference, as described in Finding Information about CAF Controls.
Copyright © 2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback