In this recipe, you will see how to add a new configuration to the portlet so that you can use the WebUI extensions.
To extend the portlet, you need to create a new XML configuration file for WebUI, add the path of this file in the
init parameters of your portlet.xml
file, and modify your portlet class.
Here are the basic steps to create a WebUI in an existing project:
WEB-INF
folder of your web application, create a folder named /conf/portlet
followed by the name of the web application, then the name of the portlet and the path /webui/configuration.xml
: MyApplication.war/WEB-INF/conf/portlet/MyApplication/MyPortlet/webui/configuration.xml
Here is a basic example of configuration.xml
:
<webui-configuration> <ui-component-config> <type> my.sample.MyPortlet </type> <lifecycle> org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle </lifecycle> </ui-component-config> <application> <ui-component-root> my.sample.MyPortlet </ui-component-root> <state-manager> org.exoplatform.webui.application.portlet.ParentAppStateManager </state-manager> </application> </webui-configuration>
portlet.xml
file:<portlet-class> org.exoplatform.webui.application.portlet.PortletApplicationController </portlet-class> <init-param> <name>webui.configuration</name> <value>/WEB-INF/conf/portlet/MyApplication/MyPortlet/webui/configuration.xml </value> </init-param>
org.exoplatform.webui.core.UIPortletApplication
class as follows:public class MyPortlet extends UIPortletApplication { ... }
Now you are ready to work with WebUI.
The
PortletApplicationController
does the initial work. This class extends the JSR 286 GenericPortlet
and wraps WebUI behind the configuration done in the portlet.xml
.
If you decide to use WebUI, remember that your class cannot extend the javax.portlet.GenericPortlet
class directly, as it is used to implement the JSR 286, and neither has the sense to implement the javax.portlet
.
Portlet
interface . You must either use the PortletApplicationController
or extend it. The reason is that the eXo framework has no concept of a portlet container. Only recently has the JBoss community added in the container, thus bringing big advantages to the portal.
The PortletApplicationController
passes the webui.configuration
to the internal Configuration Manager of WebUI, which will process the configuration described in the configuration.xml
.
In configuration.xml
, we have the following two blocks:
ui-component-config
: This is used to configure the specific component. You can add several components to the application. In the example, the Configuration Manager assigns a lifecycle to the component MyPortlet
. The lifecycle acts on the component and executes some of the component's operations, as will be seen in the next paragraph.application
: This manages the whole application. In the example, the application is represented by the same component MyPortlet
because MyPortlet
extends the UIPortletApplication
class, which is an extension of the UIContainer
. It's possible to use a different application that will contain other components. In the example, a State
Manager is assigned to the application. The State Manager is mandatory in the configuration and manages the saving and the loading of the state of the components. The State Manager provides three operations. They are described in the main class, org.exoplatform.webui.application.StateManager
:
abstract public class StateManager { abstract public UIApplication restoreUIRootComponent(WebuiRequestContext context) throws Exception; abstract public void storeUIRootComponent(WebuiRequestContext context) throws Exception; abstract public void expire(String sessionId, WebuiApplication app) throws Exception; }
restore
operation loads the component from a store and maintains it in memory.store
operation is used to save the configuration of the component along with the information of the user who reads it in the HTTP session.expire
operation is never used, but it would be used to force the deletion of the component from the HTTP session. Only a custom State Manager can use it.The State Manager is hierarchic. It will be used by all components and parent components. It is due to the State Manager that you will see the correct representation of the components in the page.
There are two implementations of State Manager:
org.exoplatform.portal.application.PortalStateManager
org.exoplatform.webui.application.portlet.ParentAppStateManager
The
ParentAppStateManager
is a wrapper for the PortalStateManager
. Always set the ParentAppStateManager
method in your configuration. Since this class is a wrapper, you can use this class in GateIn 3.2, 3.3, 3.4, and so on.
You will now see some details of the base configuration seen in the preceding paragraph.
Many components are provided by WebUI, so you will see a list of the main components to use:
org.exoplatform.portal.webui.application.UIPortlet
: Represents a portlet. It is not a JSR 286 portlet, but it provides all the features.org.exoplatform.portal.webui.portal.UIPortal
: Represents a portal. It manages information such as default skin, public parameters, edit permissions, navigation path, and default locale.org.exoplatform.portal.webui.workspace.UIPortalApplication
: Represents a generic application inside the portal. It manages the information of the current portal where it is installed.org.exoplatform.webui.core.UIPortletApplication
: Represents the base portlet. It excludes many features with respect to the UIPortlet.org.exoplatform.webui.core.UIComponentDecorator
: Represents individual components that can be integrated in the pages or in the application. Examples of extensions include the pop-up window, the page body, the graphic panel, and so on. org.exoplatform.webui.form.UIForm
: Represents a generic form. With it, you can configure the parameters, the HTTP method, the encoding, the action, and the events.org.exoplatform.webui.core.UIContainer
: Represents the container used by the portlet and by the other applications. Basically, it implements a tree containing other UI components represented as children. The UIForm
is a container because it contains form parameters.These are the basic components in WebUI. As there are numerous components available in WebUI, it is difficult to cover all of them in this book; however, we will consider some of them. A better way to know them all is to use a Java development tool and find all extensions of the org.exoplatform.webui.core.UIComponent
class . By using this method, you will find the component you need
Instead of the XML file, you can use
Java annotations in your class. Each XML tag in WebUI uses respective annotation. For example, instead of ui-component-config
you can use the ComponentConfig
annotation . This is the respective configuration:
@ComponentConfig( type = MyPortlet.class, lifecycle = UIApplicationLifecycle.class) public class MyPortlet extends UIPortletApplication { ... }
Here is an example of multiple annotated configurations:
@ComponentConfigs({ @ComponentConfig(...), @ComponentConfig(...) })
The order of execution is done as first by the annotation, and then by the XML configuration. If the XML is not present, the valid configuration will be done by the annotation. If both are present, the XML will rewrite the present annotations, or it will add new tags if present only in the annotation. It is good practice to use only one type to avoid confusion.
If you use the
ui-component-config
tag, you must set the lifecycle.
GateIn provides a wide set of lifecycles for your application. Basically, you have a ClassCastException
if you don't set the right lifecycle, so take care when you set a lifecycle. Each lifecycle is written for the type of component that your component extends.
These are the basic methods for the lifecycle:
public class Lifecycle<E extends UIComponent> { ... processDecode(...) // generic operations of decode of the outputStream ... processAction(...) // processor for the actions. For example can read the http url and pass the parameters to the action class ... processRender(...) // executes the rendering of the page, for example adding custom html div or javascript contents ... renderTemplate(...) // executes the rendering of a view loading a groovy template through a templating service }
Each component has a proper mode to execute these operations.
In the following, you can see the relative components for the page, portal, form, portlet, application, and container. Simply choose the lifecycle according to the type of component you write:
org.exoplatform.portal.webui.application.UIPortletLifecycle<S, C, I>
- org.exoplatform.portal.webui.application.UIPortlet
org.exoplatform.portal.webui.page.UIPageLifecycle
- org.exoplatform.webui.core.UIComponent
org.exoplatform.portal.webui.portal.UIPortalLifecycle
- org.exoplatform.portal.webui.portal.UIPortal
org.exoplatform.portal.webui.workspace.UIPortalApplicationLifecycle
org.exoplatform.portal.webui.workspace.UIPortalApplication
org.exoplatform.webui.core.UIComponentDecoratorLifecycle
- org.exoplatform.webui.core.UIComponentDecorator
org.exoplatform.webui.core.lifecycle.UIFormLifecycle
- org.exoplatform.webui.form.UIForm
org.exoplatform.webui.core.lifecycle.UIContainerLifecycle
- org.exoplatform.webui.core.UIContainer
org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle
- org.exoplatform.webui.core.UIPortletApplication
3.12.162.37