+

Search Tips   |   Advanced Search

Move or insert Nodes

To move existing nodes or insert new nodes, use the insert() method of the controller. When creating a node, we must insert it into the topology of the model, for example, to make it visible and accessible for users. Operations defined on the controller itself, such as hasChildren() or getLayoutModelController(), work only after you insert the node.

  1. Obtain an appropriate controller.

  2. Identify the target location in the topology.

  3. Identify the resource to move or insert as follows:

    • For moving a resource, locate an existing node with the appropriate locators of the controller.

    • For inserting a resource, create a modifiable instance representing a new resource.

  4. Insert the resource into the topology of the controller using its insert() method and by specifying its target location.

    This resource can be one of the following list:

    • A parent node.

      In this case, the resource is inserted as the last child of the parent node.

    • A parent node and a sibling node.

      In this case, the resource is inserted as the child of the parent node in a position immediately before the sibling node.

    • No location information at all.

      In this case, the resource is inserted as a new root. This insertion is not possible for all controllers. For example, we cannot insert a new root node into a ContentModelController that has a root node already.

  5. Persist the modifications using the commit() method of the controller.


Example

Move an existing portlet to a different container (error handling omitted):

// obtain locator of LayoutModelController
final Locator locator = lmController.getLocator();

 // locate portlet and target containers
final LayoutControl control = (LayoutControl) locator.findByUniqueName("MyControl");
final LayoutContainer parentContainer = (LayoutContainer) locator.findByUniqueName("MyParentContainer");
final LayoutContainer nextContainer = (LayoutContainer) locator.findByUniqueName("MyNextContainer");

 // move portlet under parentContainer just before nextContainer
lmController.insert(control, parentContainer, nextContainer);


See


Parent Modify portal resources and topologies