28-Oct-06 (Created: 28-Oct-06) | More in 'Java-Portlets'

Samplecode: Hello world portlet

Source code


package com.indent.portals.test;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;


public class SatyaHelloWorldPortlet extends GenericPortlet {

   public void processAction(ActionRequest req, ActionResponse res)
      throws IOException, PortletException {
   }

   public void doView(RenderRequest req, RenderResponse res)
      throws IOException, PortletException {

      res.setContentType("text/html");

      res.getWriter().print("Satya Hello World!");
   }
}

Portlet definition


   <portlet>
      <portlet-name>satya-portlet-1</portlet-name>
      <display-name>Satya Hello World</display-name>
      <portlet-class>com.indent.portals.test.SatyaHelloWorldPortlet</portlet-class>
      <expiration-cache>0</expiration-cache>
      <supports>
         <mime-type>text/html</mime-type>
      </supports>
      <portlet-info>
         <title>Satya Hello World</title>
         <short-title>Satya Hello World</short-title>
         <keywords>Satya Hello World</keywords>
      </portlet-info>
      <security-role-ref>
         <role-name>power-user</role-name>
      </security-role-ref>
      <security-role-ref>
         <role-name>user</role-name>
      </security-role-ref>
   </portlet>