Share

Setting preferences in the Liferay Way

UseCase: I have a one form and it has set fields like
1. Project
2. IssueType
3. Summary
4. Priority

Now i will create a preferences page where user has provision to select which fields has to show in the form or which fields user wants to give values.
In the preferences page if a user checks a particular field check box then that field will show in the form.

Now lets go technically how we can do this one.

1.Create one portlet

2. Insert the below line in liferay-portlet.xml between icon tag and schedule-entry tag.
          
                   com.liferay.portal.kernel.portlet.DeafaultConfigurationAction
               
3. Then deploy the portlet and observe the changes in the UI by clicking the Configuration in the portlet settings.New "setup "tab has added in the popup and new option "Archive/Restore setup"


4. Open "portlet.xml"and define a new "init-param"  with "name" as "config-template" and value as "/html/config.jsp"

          config-template
          /html/config.jsp
     
Inside tag entry following line

config
     

5. Now open config.jsp and Add the following code
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="com.liferay.portal.kernel.util.GetterUtil"%>
<%@include file="init.jsp" %>
Show Fields

There are two important things that note here

1.Inside the form have to define a hidden field.With out this the preferences will not be saved into the
portletPreferences table.
2.Any preference that you want to set should be prefixed by "preferences--" and suffixed by "--."
This will help the processAction method of the ConfigurationAction class to process only
those fields and properly store them to database.


6. Now open view.jsp and Add the following code
<%@page import="com.liferay.portal.kernel.util.GetterUtil"%>
<%@include file="/html/init.jsp"%>

Portlet Preferences

Project Issue Type
Summary Priority

No comments:

Post a Comment