Send Redirect in Liferay


Today we will discuss how to redirect from a portlet to another portlet which are placed on some other page. For this we need two things:-

1)Portlet Layout Id(plid)
We need the plid of the page where we want to redirect.We can get the plid by the page name as:-



2)Portlet Name
We can get the Portlet name (on which we have to redirect) by clicking on wheel icon of portlet than go to look and feel and than click on advance Styling.




So lets start this step by step:-


Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as send-redirect and click finish. After that Right Click on your project ie send-redirect and click on New than click on Liferay Portlet. Provide class name as Demo and select MVCPortlet and click finish.

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


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


Explanation:-
Here we create a simple form on submit of form sendAction method is called inside controller.


Step 3:-Create Second Portlet
Right Click on project and click on New than click on Liferay Portlet.Give Portlet Name as Result and also change jsp name to result.jsp.


Step 4:-Deploy Result Portlet
Deploy the Result portlet and add to any page in my case i am adding this to a public page named about. Now get the Portlet name by going to look and Feel as discussed above. In my case the portlet name is result_WAR_sendredirectportlet.



Step 5:-Change Controller of Demo Portlet
Open Demo.java and Paste this Content:-


Explanation:-

  • Here first we get the plid and than create a URL and send redirect to another page using plid.
  • we also send a parameter so that this can be used in another portlet.
  • For more detail on LayoutLocalServiceUtil you may refer my blog add Portlet and Change Layout Programmatically.

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


Explanation:-
Here we just print the value that is set in Demo.java .



For Output


Now deploy both Demo and Result portlet and add Demo Portlet to welcome page and Result Portlet to about page .

When you click on submit it will redirect to Result Portlet which is placed on about page.


Project Structure



Hope this will Help....

You can Download Source code from  Send Redirect in Liferay.











Related Post:-