+

Search Tips   |   Advanced Search

Move or Inserting Nodes


To move existing nodes or insert new nodes, use the insert() method of the controller.

  1. When creating a new node, you need to insert it into the topology of the model, for example, to make it visible and accessible for users.

  2. Operatione definedd on the controller itself, such as hasChildren() or getLayoutModelController(), work only after you insert the node.
To move or insert nodes...

  1. Obtain an appropriate controller.

  2. Identify the target location in the topology. You will neethat information in a later step.

  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 that represents a new resource.

  4. Insert the resource into the topology of the controller using its insert() method and by specifying its target location. this can be one of the following:

    • 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 is not possible for all controllers.

      For example, we cannot insert a new root node into a ContentModelControllethat has a root node already.

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

Example 1 - Moving 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);


Parent: Modify portal resources and topologies
Related:
Create resources
Delete Nodes