Chapter 5. Deploying Custom Portlets

5.1. Introduction

This section described the steps to incorporate your own portlets in to JBoss Portal.

5.2. Assumptions

Assumptions:

  1. You already have a portlet war named helloworld.war
  2. The WAR file has a standard directory structure:
                /helloworld.war
                   /WEB-INF
                      /classes
                      /lib
                      /portlet.xml
                      /web.xml
                   /META-INF
                
  3. Your porlet.xml looks like this:
                   <?xml version="1.0" encoding="UTF-8"?>
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
    version="1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
    http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
    <portlet>
        <portlet-name>HelloWorldPortlet</portlet-name>
        <portlet-class>com.myapp.portlet.HelloWorldPortlet</portlet-class>
        <expiration-cache>0</expiration-cache>
        <supports>
          <mime-type>text/html</mime-type>
          <portlet-mode>help</portlet-mode>
        </supports>
        <supported-locale>en</supported-locale>
        <portlet-info>
          <title>Hello World Portlet</title>
        </portlet-info>
      </portlet>
    </portlet-app>
                   

5.3. Adding the XML Descriptors

There are two files you will need to add under /WEB-INF for your portlet to work in Jboss Portal. The first is a helloworld-pages.xml. The portal will scan this file to find out which portal instance to target and what page name it will be in. In this case, we can access our portlet by going to http://localhost:8080/portal/index.html?page=hello

<pages>
   <portal-name>default</portal-name>
   <page>
      <page-name>hello</page-name>
      <window>
         <window-name>HelloWorldPortletWindow</window-name>
         <instance-ref>/portal-hello.HelloWorldPortlet.HelloWorldPortletInstance</instance-ref>
         <default>true</default>
         <region>user1</region>
         <height>0</height>
      </window>
   </page>
</pages>
         

The second file needed under /WEB-INF is a portlet-instances.xml. This file maps the portlet name in your portlet.xml file to the portlet instance in your helloworld-pages.xml.

<?xml version="1.0" standalone="yes"?>
<instances>
   <instance>
      <instance-name>HelloWorldPortletInstance</instance-name>
      <component-name>HelloWorldPortlet</component-name>
   </instance>
</instances>
         

Now add these two files to your war and you should be able to access the helloworld portlet by going to http://localhost:8080/portal/index.html?page=hello.