Placing a portlet on a page
To put a portlet on a page, use the insert() method of the controller.
To place a portlet on a page...
- Obtain a layout model controller for the page the portlet is to be put on.
- Obtain a LayoutControlCreationContext; this includes obtaining the portlet definition ID, and optionally the portlet entity ID.
- Create a layout control using the context from the previous step and using the create() method of the layout model controller.
- Insert the created layout control into the layout model controller.
- Persist the modifications using the commit() method of the controller.
Example 1 - Placing a portlet on a page:
// obtain layout model controller final LayoutModelController lmController = cmController.getLayoutModelController(page); // obtain layout control creation context final LayoutControlCreationContext context = ... (portletDefinition, null); //final LayoutControlCreationContext context = ... (portletDefinition, portletEntity); // create layout control final Modifiable control = lmController.create(LayoutControl.class, context); // insert control into the topology of the layout model controller (given a container and a sibling) lmController.insert(control, container, sibling); // commit the content model controller cmController.commit();
Parent: Move or Inserting Nodes