eXo Platform 4.0 Documentation > Developer Guide > Developing Applications > Developing a portlet

5.2.1. HelloWorld portlet

In this part, you will create a very basic portlet. It contains a simple JSP page.

  1. Create a new Maven project as follows:

  2. Edit pom.xml:

    
    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.acme.samples</groupId>
      <artifactId>hello-portlet</artifactId>
      <version>1.0</version>
      <packaging>war</packaging>
      <build>
        <finalName>hello-portlet</finalName>
      </build>

      <dependencies>
        <dependency>
          <groupId>javax.portlet</groupId>
          <artifactId>portlet-api</artifactId>
          <version>2.0</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </project>
  3. Edit WEB-INF/web.xml:

    
    <web-app>
      <display-name>hello-portlet</display-name>
    </web-app>
  4. Edit WEB-INF/portlet.xml:

    
    <portlet-app version="2.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
      <portlet>
        <portlet-name>Hello</portlet-name>
        <portlet-class>com.acme.samples.HelloPortlet</portlet-class>
        <supports>
          <mime-type>text/html</mime-type>
        </supports>
        <portlet-info>
          <title>Hello</title>
        </portlet-info>
      </portlet>
    </portlet-app>
  5. Edit HelloPortlet.java:

    package com.acme.samples;
    
    
    import java.io.IOException;
    import javax.portlet.GenericPortlet;
    import javax.portlet.PortletRequestDispatcher;
    import javax.portlet.RenderRequest;
    import javax.portlet.RenderResponse;
    import javax.portlet.PortletException;
    import javax.portlet.RenderMode;
    public class HelloPortlet extends GenericPortlet {
      @RenderMode(name = "view")
      public void Hello(RenderRequest request, RenderResponse response) throws IOException, PortletException {
        PortletRequestDispatcher prDispatcher = getPortletContext().getRequestDispatcher("/jsp/hello.jsp");
        prDispatcher.include(request, response);
      }
    }
  6. Edit jsp/hello.jsp:

    <h2>Hello</h2>
    <h6>Welcome to Hello portlet!</h6>
    <p><i>Powered by eXo Platform.<i><p>

After being built, the package should be target/hello-portlet.war. Go to next section to deploy it in eXo Platform.

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