Events

Liferay Release Dashboard

Get information and status on past, present, and future Liferay releases.

A Free Template from Joomlashack

A Free Template from Joomlashack

Advertisement

Liferay Configuration Mode PDF Print E-mail
Written by Sanjay Kannan   
Sunday, 22 November 2009 00:15


In any portal product, whether its liferay or WebSphere Portal, a portlet mode advises the portlet what task it should perform and what content it should generate. Portlet has three modes - View, Edit and Help mode. One can add additional custom mode like Config & edit_defaults mode. This article will explain how to enable config mode in liferay. 

Lets look at the Liferay Portlet application structure and what steps are required to enable the config mode.

 Liferay Portlet Application Structure

If you notice in the picture above there are two additional xml files which are specific to Liferay.

1. liferay-portlet.xml - liferay specific portlet attributes
2. liferay-display.xml - portlet category specification

 In the liferay-portlet.xml, specify the configuration-action-class xml element. Here you specify the configuration mode implementation class.

<portlet>
<portlet-name>LiferayConfigModePortlet</portlet-name>
<configuration-action-class>com.skzine.liferay.portlet.ConfigurationActionImpl</configuration-action-class>
<instanceable>true</instanceable>
</portlet>

Lets look at the configuration mode implementation class 

  •  ConfigurationActionImpl extends BaseConfigurationAction. The base class can be found in portlet-kernel.jar
  • Implement the two methods processAction & render
  • These two methods takes in PortletConfig, ActionRequest/RenderRequest, ActionResponse/RenderResponse as paramteres.
  • In the render method return the configuration page we created for the config view (return "/WEB-INF/jsp/Configuration.jsp";)
Once all the above configuration is done, we are ready to deploy the portlet and see the configuration page.
 
 Liferay config View
Submitting a form in Configuration Page 
 
Lets look at how we can submit a form in the configuration jsp.
 
<form action='<liferay-portlet:actionURL portletConfiguration="true" />' method="post"></form> 
 
If you look at the action parameter, liferay provides a mechanism to generate a portlet url to the configuration page. This is important so that the form is submitted to the configuration implementation class which we have written above.
 
 Storing Preferences in Configuration mode
 
For storing any information in preferences, liferay provides api. Below is the code to use to store and retrieve preferences in config mode.
 
//Storing preferences 
String portletResource = ParamUtil.getString(actionRequest, "portletResource");
PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
preferences.setValue("pref-name", name);
preferences.store(); 

//Retreiving preferences 
String param_name = preferences.getValue("pref-name",""); 
 
You can download the source code here


Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! TwitThis Joomla Free PHP
Last Updated on Sunday, 22 November 2009 11:05
 
 
Joomla 1.5 Templates by Joomlashack