Overview
- Home
- Portlet Concepts
- Portlet Classes
- Portlet TagLib
- JavaDocs
- Portlet DTD
- Download
Writing Portlets
- Hello World
- Portlet with Action
- More examples
Project
- Mailing Lists
- Source Repository
- Issue Tracking
- Project Team
- Road Map
Portlet Catalog
- Basic Portlet
- Bookmarks
- RSS Feed
- Menu
- Login/Logout
- Poll
- Google Search
- Discussion Forum
- Contacts
- Calendar
- Email Client
- Document Manager
Misc.
- Setup jPortlet Project
- Server Side Include
- Internationalization
- Portlet Actions
- Changing Look & Feel
|
Overview
|
We are going to create a HelloWorld portlet.
This portlet supports:
- Markups
- HTML (VIEW, EDIT, HELP and CONFIGURE)
- Language
- English
|
|
1. Setup the project
|
Goto here to setup the project directory
|
|
2. Write the Portlet
|
Now that the project is setup, you should create the portlet class inside
PROJECT_HOME/src/java/ directory
HelloPortlet.java |
package net.sf.jportlet.samples.hello;
import java.io.IOException;
import net.sf.jportlet.portlet.PortletAdapter;
import net.sf.jportlet.portlet.PortletException;
import net.sf.jportlet.portlet.PortletRequest;
import net.sf.jportlet.portlet.PortletResponse;
public class HelloPortlet
extends PortletAdapter
{
protected void doView( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
response.getWriter( ).println( "Hello world" );
}
protected void doHelp( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
response.getWriter( ).println( "This example shows how to create a very basic portlet" );
}
protected void doConfigure( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
response.getWriter( ).println( "Nothing to configure" );
}
protected void doEdit( PortletRequest request,
PortletResponse response )
throws PortletException,
IOException
{
response.getWriter( ).println( "Nothing to edit" );
}
}
|
|
|
3. Write the deployment descriptors
|
Now that the portlet are created, you must describe them in the jPortlet deployment descriptor.
The jPortlet deploment descriptor MUST be named portlet.xml and MUST be located in the
WEB-INF/ directory of the web application.
portlet.xml |
<?xml version="1.0"?>
<!DOCTYPE portlet-app SYSTEM "http://jportlet.sourceforge.net/dtd/portlet-1.0.dtd">
<portlet-app>
<portlet-app-name>HelloWold</portlet-app-name>
<portlet>
<portlet-name>hello</portlet-name>
<portlet-class>net.sf.jportlet.samples.hello.HelloPortlet</portlet-class>
<default-locale>en</default-locale>
<language locale="en">
<title>Hello</title>
<title-short>hello</title-short>
<description>Simple Hello World portlet</description>
</language>
<supports>
<markup name="html">
<view />
<edit />
<configure />
<help />
</markup>
</supports>
</portlet>
</portlet-app>
|
|
|
4. Put the portlet in the Web-application
|
Now that the portlet is created, you must create a JSP file that will show your its content.
Create the file PROJECT_HOME/src/web/jsp/index.jsp .
index.jsp |
<%@ taglib uri="/WEB-INF/jportlet.tld" prefix="jportlet" %>
<jportlet:page width="100%" title="Hello World">
<jportlet:body>
<jportlet:portlet name="hello" returnURI="/hello/index.jsp"/>
</jportlet:body>
</jportlet:page>
|
|
|
5. Build, deploy and test
|
Run the following commands from the source directory from PROJECT_HOME/src/ :
-
ant This will compile all the files and generate the project .war file
-
ant deploy This will deploy the .war file into the application server.
- Navigate to http://localhost:8080/jportlet-hello
|
|
|