Move or Inserting Nodes
To move existing nodes or insert new nodes, use the insert() method of the controller.
To move or insert nodes...
- 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.
- Operatione definedd on the controller itself, such as hasChildren() or getLayoutModelController(), work only after you insert the node.
- Obtain an appropriate controller.
- Identify the target location in the topology. You will neethat information in a later step.
- 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.
- 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.
- 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);
- Placing a portlet on a page
To put a portlet on a page, use the insert() method of the controller.
Parent: Modify portal resources and topologies
Related:
Create resources
Delete Nodes