Thursday, October 8, 2015

Portlet Configuration Page in Liferay using Custom Class

We already discuss about Portlet Configuration page using DefaultConfiguration class provide by liferay. In this blog we create the same application but by using our own custom class.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.

Note:-You can check the snapshots in my previous blog on Portlet Configuration Page in Liferay.

Step 3:-Create Configuration Jsp
Open html/demo package and create a jsp with name configuration.jsp and paste this content:-

Here we just create a simple form with 4 check box. We create a actionUrl with portletConfiguration="true" so that it will call Configuration class processAction method and not of portlet processAction method.

Step 4:-Create Configuration Class
Open com.demo package a create a java class with name ConfigurationAction that extends DefaultConfigurationAction
Now override the processAction() and render() as:-

1)Here we just fetch the values and set in Preferences.
2)Render method just redirect the flow to configuration.jsp.
3)The last line in Action Method refresh the page so that when we go back to page new result is shown.

Step 5:-Enable SetUp tab
Provide a entry in liferay-portlet.xml so that set up tab is enable and when we click on set up tab our Configuration Class is Called. Open liferay-portlet.xml and after <icon> tag paste this


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

Here we just fetch the values from preferences and show the column if value is true. Here we use jstl tags so provide the jstl entries 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.

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!