Wednesday, May 11, 2011

Adding language selection portlet to the Dockbar using custom jsp hook plugin

The Liferay Language portlet provide an option to select from different localizations. It’s a common requirement in web application to display language selection option as flags in the header area.

In Liferay we can accomplish this through hook plugin as following:

1. Create a Liferay hook plugin project create sample-hook "Sample Dockbar Hook"

2. In the /docroot/WEB-INF/ folder open liferay-hook.xml file and add the following entry

<hook>

<custom-jsp-dir>/WEB-INF/jsps</custom-jsp-dir>

</hook>

3. Copy ${PORTAL_ROOT_HOME}htmlportletdockbarview.jsp to ${liferay.plugins.sdk}sample-hookdocrootWEB-INFjspshtmlportletdockbar folder.

4. Add the following code after Toggle Edit Control

<liferay-ui:language displayStyle="0" languageIds='<%= new string[] {"en_US","nl_NL"} %>' />

This will add English and Dutch Language to the dockbar.

5. Build and package the hook WAR file and deploy it on your Liferay server.

Friday, May 6, 2011

Adding Portlet Preferences to Custom Portlet

The portlet preferences are intended to store basic configuration data for portlets. The PortletPreferences interface allows the portlet to store configuration data, not to replace the general-purpose databases.
Normally, there are two different types of preferences: Modifiable and Read Only.
Modifiable preferences can be changed by the portlet in any standard portlet mode (for example, EDIT, HELP, and VIEW). While Read-Only preferences cannot be changed by the portlet in any standard portlet mode, they may be changed by administrative modes.

By default, preference is modifiable.

Following are the steps to add portlet preferences (configurations) to custom portlet:

1. Add a configuration.jsp file:


2. Create an ConfigurationActionImpl class :


3. Made an entry in liferay-portlet.xml file:

<configuration-action-class>ConfigurationActionImpl</configuration-action-class>

4. Just Fetch and use the preferences:


5.Adding Preferences Default Value  to Portlet.xml:



In this way you can add any configuration options to the portlet and persist them portlet preferences.

If you have any questions or query, Please comment.....