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. language-ext.properties     (ext/ext-impl/src/content/)

1. portlet-ext.xml
<portlet>
    <portlet-name>JSP Portlet</portlet-name>
    <display-name>JSP Portlet Introduction</display-name>
    <portlet-class>com.liferay.util.bridges.jsp.JSPPortlet</portlet-class>
    <init-param>
        <name>view-jsp</name>
        <value>/html/portlet/ext/jsp_portlet/view.jsp</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
        <mime-type>text/html</mime-type>
    </supports>
    <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>
    <security-role-ref>
        <role-name>power-user</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>user</role-name>
    </security-role-ref>
</portlet>

2. liferay-portlet-ext.xml
<portlet>
    <portlet-name>
JSP_Portlet</portlet-name>
</portlet>

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

4. language-ext.properties
javax.portlet.title.Sample=JSP Portlet
newcategory.category1=
NewCategory


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...