Liferay Struts Portlet Development – 1


Liferay Simple Struts Portlet Development

  1. create portlet entry in “portlet-ext.xml”

<portlet>

<portlet-name>libraryhome</portlet-name>

<display-name>Library Home</display-name>

<portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>

<init-param>

<name>view-action</name>

<value>/ext/library/viewhome</value>

</init-param>

<expiration-cache>0</expiration-cache>

<supports>

<mime-type>text/html</mime-type>

</supports>

<portlet-info>

<title>Library Home</title>

<short-title>Library Home</short-title>

<keywords>library</keywords>

</portlet-info>

<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.Create liferay specific portlet entry in “liferay-portlet-ext.xml”

<portlet>

<portlet-name>libraryhome</portlet-name>

<struts-path>ext/library</struts-path>

<use-default-template>false</use-default-template>

</portlet>

  1. Create “/ext/library/viewhome” struts pageflow in struts-config.xml for the entry ‘<value>/ext/library/viewhome</value>’ in portlet-ext.xml

<action path=“/ext/library/viewhome” forward=“portlet.ext.library.viewhome” />

4. Create tiles pagelayout for “/ext/library/viewhome” – struts path in tiles-defs.xml

<definition name=“portlet.ext.library” extends=“portlet” />

<definition name=“portlet.ext.library.viewhome” extends=“portlet.ext.library”>

<put name=“portlet_content” value=“/portlet/ext/library/view_home.jsp” />

</definition>

  1. Create JSP file view_home for the pageto be displayed

    <%@ include file=“/html/portlet/ext/library/init.jsp” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” http://www.w3.org/TR/html4/loose.dtd&#8221;>

<html>

<head>

<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>

<title>Library Home</title>

</head>

<body>

Library Home

<br> <h3>Home Page &nbsp;&nbsp;&nbsp;&nbsp; will be used entry point for Libarary Process </h3>

</body>

</html>

  1. Include init.jsp /html/portlet/ext/library/init.jsp

    This is for our portlet initialization parameter or preferences …

  1. init.jsp

// this is for liferay, xtra tags file to be used in our jsp while development .. Eg: image tag, display tag, etc …

<%@ include file=“/html/common/init.jsp” %>

<portlet:defineObjects />

<%

WindowState windowState = renderRequest.getWindowState();

%>

  1. End..

    Create a category, and add this..

    Enjoy

Struts portlet with Struts Action will be available in Next Post

-live

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s