Monday, August 10, 2009

Creating simple struts Portlet in liferay in 5 min

In struts portlet as compare to Jsp portlet we need to add 2 extra xml files

1.struts-config.xml
2.tiles-defs.xml

We have to modify follwing xml files.

These xml files are located under "ext/ext-web/docroot/WEB-INF"

2.1. portlet-ext.xml
--------------------

<portlet>
<portlet-name>Sample</portlet-name>
<display-name>Sample Struts Portlet</display-name>
<portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>
<init-param>
<name>view-action</name>
<value>/ext/sample/view</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.2. liferay-portlet-ext.xml
----------------------------

<portlet>
<portlet-name>Sample</portlet-name>
<struts-path>ext/sample</struts-path>
<use-default-template>false</use-default-template>
</portlet>

2.3. liferay-display.xml
------------------------

add

<portlet id="Sample" />

inside

<category name="category.sample">

2.4. struts-config.xml
----------------------

<action path="/ext/sample/view" forward="portlet.ext.sample.view" />

2.5. tiles-defs.xml
-------------------

<definition name="portlet.ext.sample" extends="portlet" />
<definition name="portlet.ext.sample.view" extends="portlet.ext.sample">
<put name="portlet_content" value="/portlet/ext/sample/view.jsp" />
</definition>


(create the following two jsp files under "/ext/ext-web/docroot/html/portlet/ext/sample")

2.6. init.jsp
-------------

<%@ include file="/html/portlet/init.jsp" %>

2.7. view.jsp
-------------

<%@ include file="/html/portlet/ext/sample/init.jsp" %>
Simple Struts Portlet!

2.8 Language-ext.properties
---------------------------

Add a new entry in the above file,

javax.portlet.title.Sample=Sample Struts Portlet

3 comments:

Unknown said...

you forgot add PortalClassLoader

Unknown said...

I think whatever I have written is enough in ext environment to create portlet.

Anonymous said...

where is your Action, ActionForm,ActionServlet and ActionMapping????