Total Pageviews

Friday, August 13, 2010

Simple JSP Portlet in Liferay

The simplest kind of portlet is a JSP portlet that displays text, data, and images, with no interactive capabilities.
For the same purpose, we have to make changes in following 4 files, and create two new JSP file, whose contents are displayed within the portlet (we'll discuss it in end of this post). These 4 files are:
  1. portlet-ext.xml  (/ext/ext-web/docroot/WEB-INF/)
  2. liferay-portlet-ext.xml   (/ext/ext-web/docroot/WEB-INF/)
  3. liferay-display.xml    (/ext/ext-web/docroot/WEB-INF/)
  4.     (ext/ext-impl/src/content/)

1. portlet-ext.xml
    <portlet-name>JSP Portlet</portlet-name>
    <display-name>JSP Portlet Introduction</display-name>

2. liferay-portlet-ext.xml

3. liferay-display.xml
<category name="newcategory.category1">
    <portlet id="MyJSPPortlet" />

javax.portlet.title.Sample=JSP Portlet

The two files that we need to make, are init.jsp and view.jsp. init.jsp plays a big role in whole portlet lifecycle (here I am giving just an overview of this file, will write a dedicated post on it) and view.jsp is a file which is the page to be displayed within the portlet.
  1. init.jsp (ext/ext-web/docroot/html/..)
  2. view.jsp (ext/ext-web/docroot/html/..)
1. init.jsp
<%@include file="/html/portlet/init.jsp"%>

2. view.jsp
Write some JSP page here (I hope you can do that :) )

then deploy and Enjoy...