KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > HelloWorldPortlet


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please visit http://www.exoplatform.org for more license detail. *
4  **************************************************************************/

5
6 import java.io.IOException JavaDoc;
7
8 import javax.portlet.* ;
9 /**
10  * The simplest portlet ever!
11  *
12  * <p>
13  * Date: May 25, 2003 Time: 11:26:44 PM
14  * </p>
15  *
16  * @author Mestrallet Benjamin
17  * @version $Revision: 1.2 $
18  */

19 public class HelloWorldPortlet extends GenericPortlet {
20   private static final String JavaDoc HELLO_TEMPLATE =
21     "/WEB-INF/templates/html/HelloWorld.jsp";
22
23   /**
24    * A life cycle method. This method gets inovked by the container.
25    *
26    * @param pConfig a object that holds the portlet configuration information
27    *
28    * @throws PortletException an exception that you throw if things go wrong
29    * while starting the portlet
30    */

31   public void init(PortletConfig pConfig) throws PortletException
32   {
33     super.init(pConfig);
34   }
35
36   /**
37    * The GenericPortlet calls this method if the portlet mode is view
38    *
39    * @param pRequest the request
40    * @param pResponse the response
41    *
42    * @throws PortletException
43    * @throws IOException
44    */

45   public void doView(RenderRequest pRequest, RenderResponse pResponse)
46     throws PortletException, IOException JavaDoc
47   {
48     WindowState state = pRequest.getWindowState();
49     pResponse.setContentType("text/html");
50
51     PortletContext context = getPortletContext();
52     PortletRequestDispatcher rd = context.getRequestDispatcher(HELLO_TEMPLATE);
53     rd.include(pRequest, pResponse);
54   }
55
56   /**
57    * The GenericPortlet calls this method if the portlet mode is edit
58    *
59    * @param pRequest the request
60    * @param pResponse the response
61    *
62    * @throws PortletException
63    * @throws IOException
64    */

65   public void doEdit(RenderRequest pRequest, RenderResponse pResponse)
66     throws PortletException, IOException JavaDoc
67   {
68     WindowState state = pRequest.getWindowState();
69     pResponse.setContentType("text/html");
70
71     PortletContext context = getPortletContext();
72     PortletRequestDispatcher rd = context.getRequestDispatcher(HELLO_TEMPLATE);
73     rd.include(pRequest, pResponse);
74
75   }
76
77
78   /**
79    * The GenericPortlet calls this method if the portlet mode is help
80    *
81    * @param pRequest the request
82    * @param pResponse the response
83    *
84    * @throws PortletException
85    * @throws IOException
86    */

87   public void doHelp(RenderRequest pRequest, RenderResponse pResponse)
88     throws PortletException, IOException JavaDoc
89   {
90     WindowState state = pRequest.getWindowState();
91     pResponse.setContentType("text/html");
92
93     PortletContext context = getPortletContext();
94     PortletRequestDispatcher rd = context.getRequestDispatcher(HELLO_TEMPLATE);
95     rd.include(pRequest, pResponse);
96   }
97 }
98
Popular Tags