In this post I will explain a way to develop portlets, compile with Maven 2, and deploy to Jahia Version 6. A Portlet is a web based application described by the Java specification JSR168. Jahia has the capability of integrating portlets by using their powerful Mashups Manager Tool. The idea of this integration is to run web applications embedded in a Jahia site without accessing another website to create dynamic content.
Portlet Development
- The first step is to create a standard Maven 2 project structure. To create that structure we need to run the archetype mvn archetype:generate, chose option 13 for portlets and fill the group id, artifactid, version and package.
- Change your pom.xml and make it look similar to this one.
- Open the portlet.xml and fill the portlet info section with your own data. Here Sample.
- Modify web.xml and makes it look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>
For this example we are not using more additional web resources than portlets.
- Rename the file MyPortlet.java existing in src/main/java to HelloPortlet.java and paste the following code:
- package com.mycompany.portlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* Hello World Portlet
*/
public class HelloPortlet extends GenericPortlet {
public void doView(RenderRequest req, RenderResponse res)
throws IOException, PortletException {
PrintWriter out = res.getWriter();
out.println("<h2>");
out.println("Hello World");
out.println("</h2>");
}
public void processAction(ActionRequest req, ActionResponse res)
throws IOException, PortletException {
}
} - Compile the project using Maven with the command mvn install
- Copy the generated war in the deploy folder of you application server, in case of tomcat paste the generated war into webapps folder.
Portlet Configuration in Jahia 6
- Login into Jahia administration and open the Mashup Manager Tool.
- Press the button Add new mushup and the following screen will appear.
- Click the HelloPortlet and press next.
- In the next step add a Title, Description, Keywords, Categories and a Thumbnail.
- Continue the wizard till complete it.
- Now the Portlet is ready and can be used in any portlet field created in your project.
Portlet.xml Configuration File
Let’s take a deeper view to the Portlet.xml file. This file is a deployment descriptor file that contains configuration details about portlets. Following is an example of this file with an explanation of it.
<portlet-app>
<portlet>
<description>Write here a short description about your portlet.</description>
<portlet-name>HelloPortlet</portlet-name>
<display-name>HelloPortlet Portlet</display-name>
<portlet-class>com.mycompany.portlet.HelloPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Hello Portlet</title>
<short-title>Hello Portlet</short-title>
<keywords>Hello Portlet</keywords>
</portlet-info>
</portlet>
</portlet-app
- The tag portlet contains the portlet definition.
- The description tag is an information tag that contains the description of the portlet.
- The portlet-name tag identifies the portlet within the portlet application.
- The display-name tag is the name of the portlet in our portal; this name is going to appear in the Mashup Manager Tool in Jahia.
- The portlet-class tag represents the fully qualified class name of the portlet. This class contains all the logic of the portlet.
- The tag supports provide information about which portlets modes are supported.
- The portlet-info tag contains information of the portlet and can be overridden in the resource boundle. The keywords are used by portals for searching and locating portlets.
Click here to download the complete source code.





blog comments powered by Disqus