Thursday, October 8, 2015

Portlet Configuration Page in Liferay using DefaultConfigurationAction

Portlet Configuration page in Liferay is a very handy feature by which we can store portlet related configuration at run time. Configuration page in Liferay uses preferences to store the configuration. This can be achieved by two ways:-

1)By using DefaultConfigurationAction Class.
2)By using own class that extends DefaultConfigurationAction .

In this blog we will use the first approach.Here we are created a simple table where user can configure number of columns at run time. ie Show/Hide columns at run time.

So lets start this step by step:-

Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as configure-table and click finish.

Step 2:-Create MVC Portlet inside project
Right Click on your project ie configure-table and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Step 3:-Provide Configuraion Action Class
Open liferay-portlet.xml file and provide the entry of configuration action class as:-

<configuration-action-class> com.liferay.portal.kernel.portlet.DefaultConfigurationAction

Now your liferay-portlet.xml become:-

Note:- The DefaultConfigurationAction class provide all the all the functionality to store the preferences . You can see the source code for the same.

Step 4:-Provide Configuration jsp
Open html/demo and create a jsp with name configuration.jsp and paste this content:-

1)We create a actionUrl with portletConfiguration="true" .
If it is false than this behave as normal actionUrl and invoke processAction() of portlet.And not invoke the action method of DefaultConfigurationAction class.

2)We give name of input field as preferences--propertyName--  this is must so that these are set in preferences.

3)We use a hidden field with name cmd and value update so that as soon as form submit page refresh automatically.

Note:- You can see the source code of DefaultConfigurationAction for the same.

Step 5:-Provide entry of Configuration jsp
Open portlet.xml and provide the entry of jsp created in previous step so that when we click set up the jsp open for configuration .


Here the name must be config-template.

Step 6:-Change view.jsp
Open view.jsp and paste this:-

Here we just fetch the preferences and on the basis of condition show the columns.

Note:-As we use the jstl library so add jstl jars in file as:-

Step 7:-See the Output
Now deploy the portlet and add to page and see the output as:

Now Select the fields you want to show

Now go to the page 
Now you can again go to configuration->set up and again select/deselect the number of columns.

Project Structure

Hope this will Help....

You can Download Source code from  Portlet Configuration Page.

In the next blog we will do the same thing with our own custom class. You can see my next blog on Configuration Page using own Custom Class for this.

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!