Unique Way to Save Portlet Preferences in Liferay 6.1

General Blogs April 16, 2013 By Jitendra Rajput

With Liferay 6.1 if you are using configuration mode and if you want to store form elements values in preferences then this post will definitely help you.

You can store form elements value in preferences with less efforts (as compare to version below Liferay 6.1).
You just need to follow few syntax to achieve this functionality. Lets go step by step.
Define your AUI element with below syntax

<aui:input name="preferences--showFeedTitle--" type="checkbox" value="<%= showFeedTitle %>" />

Edit :Create hidden field with the name command so that Controller will automatically understand what you are trying to do.


<input name="<portlet:namespace /><%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />


It should follow pattern like preferences--paramName-- .

And make sure you use below Configuration class in your liferay-portlet.xml


By using this way we dont need to write any code to store form element value into preferences . DefaultConfigurationAction class will detect form element with specified syntax and store the same in preference for you.

In case if you want to retrieve value from preference then directly use.


preferences.getValue("showFeedTitle", StringPool.BLANK);


Hope this will help ..!!

Jitendra Rajput


Showing 1 result.