5.2.2.5. Injecting a portlet using Dynamic Container

The mechanism

If you want to inject a portlet to every page in a site, you might add it directly to the shared layout (sharedlayout.xml). However, in case you have more than one extension that overrides sharedlayout.xml, only the last loaded one takes effect. This leads to trouble that portlets injection cannot be solved in packaging, it will require extra tasks in deployment (like merging several layouts from different projects).

As of 4.1, the trouble is solved by the Dynamic Container feature. A shared layout and an extension get involved in how it works:

So in this way, whenever the named container instance is put into a page, or all pages via sharedlayout.xml, the portlet injection is done automatically. An extension does not have to override the layout.

Example

In the following example, you inject the "Help" portlet (a built-in, for simplification) into all pages of the Intranet site. The Help portlet is already featured at the top right of the homepage by default, so you will add another one to the left.

  1. Make a portal extension as described in Portal extension section.

  2. Edit WEB-INF/conf/configuration.xml:

    
    <configuration
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
            xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">

        <external-component-plugins>
        <target-component>org.exoplatform.commons.addons.AddOnService</target-component>
        <component-plugin>
            <name>addPlugin</name>
            <set-method>addPlugin</set-method>
            <type>org.exoplatform.commons.addons.AddOnPluginImpl</type>
            <description></description>
            <init-params>
            <value-param>
                <name>priority</name>
                <value>5</value>
            </value-param>
            <value-param>
                <name>containerName</name>
                <value>left-topNavigation-container</value>
            </value-param>
            <object-param>
                <name>help-portlet</name>
                <description></description>
                <object type="org.exoplatform.portal.config.serialize.PortletApplication">
                <field name="state">
                    <object type="org.exoplatform.portal.config.model.TransientApplicationState">
                    <field name="contentId">
                        <string>platformNavigation/UIHelpPlatformToolbarPortlet</string>
                    </field>
                    </object>
                </field>
                </object>
            </object-param>
            </init-params>
        </component-plugin>
        </external-component-plugins>
    </configuration>

In which:

Default Dynamic Container instances

Here are the Dynamic Container instances in the Intranet site:

For a customized site, you can manage Dynamic Containers by customizing sharedlayout.xml. The configuration sample is given above. There are two templates of Dynamic Container:

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus