Message Boards

Links between portlets

Simone de Blasiis, modified 4 Years ago.

Links between portlets

New Member Posts: 12 Join Date: 5/14/19 Recent Posts
Hello,we are developing multiple portlets for our Liferay 7 installations and now we need to able to have to have links between two portals.
We have a list of data that is normally being inserted and visualized in a specific portlet, let's call it portlet B, and that data is also being displayed in another portlet, let's call it portlet A.
Displaying the data in a table form is quite easy because we just had to recreate the table in portlet B in portlet A. The problem is that in portlet B there's a button that allows you to open a specific jsp that has the detail of that specific object. We are trying to avoid needing to recreate even that jsp in portlet A so we were looking for ways to create cross-portlet renderUrls so that when a user on portlet A clicks on the detail button is redirected to the detail jsp on portlet B but we can't find anything about this online.Is there a way to do it?Thanks in advance to anyone that can help us
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Links between portlets

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts
Simone de Blasiis:

we were looking for ways to create cross-portlet renderUrls so that when a user on portlet A clicks on the detail button is redirected to the detail jsp on portlet B
Do not look for cross-portlet render URLs. This will tie both portlets closely together, and they're designed to be completely separated. If they share the same bundle, you may use the same JSP for the frontend, but communication between the two can be done through Interportlet Communication, e.g. Public Render Parameters (or Events).
A loooong time ago, I've conducted a webinar that demonstrated this technique. The video is linked, and one part of this is to create an application composed out of multiple portlets, having the "overview->detail" separation. While that webinar naturally has been done on an old version (being from 2014), the principle still holds (though I'd recommend to implement them according to current standards).
Simone de Blasiis, modified 4 Years ago.

RE: Links between portlets

New Member Posts: 12 Join Date: 5/14/19 Recent Posts
Hello, thanks for the reply.
I managed to implement IPC between the two portlets but now I'm stuck on what to do next.
I am able to pass data between them but nothing more than that.
In your webinar I see that you have  multiple portlets on the same page but that's not the case for me since they are two completely separated pages.
​​​​​​​Am I missing something?
thumbnail
krishna patel, modified 4 Years ago.

RE: Links between portlets

New Member Posts: 14 Join Date: 5/21/18 Recent Posts
If I am getting your question, when I click a button in portlet_B it opens a specific page. the same action should happen when you click a button from portlet_A.

For this scenario we can use below solution,

If you have same table in portlet_A and portlet_B, You can use the below URL in both portlets for onClick event. It will always point to method "viewDetail" of portlet_B. and open according to page of portletB


<liferay-portlet:renderurl var="detailURL" plid="${portletBPlId}" portletname="portletB_WAR_frontendmanagementportlet" windowstate="&nbsp; &nbsp; &nbsp; &nbsp;<%=LiferayWindowState.NORMAL.toString()%>">
&nbsp;&nbsp; &nbsp; <liferay-portlet:param name="action" value="viewDetail" />
&nbsp;&nbsp; &nbsp; <liferay-portlet:param name="id" value="CLICKED_ID" />
</liferay-portlet:renderurl>


you can get portletBPlId by:


portletBLayout = LayoutLocalServiceUtil.fetchLayoutByFriendlyURL(themeDisplay.getScopeGroupId(), false, /portlet-b-page-friendly-url);
portletBId = portletBLayout.getPlid();
Simone de Blasiis, modified 4 Years ago.

RE: Links between portlets

New Member Posts: 12 Join Date: 5/14/19 Recent Posts
First of all thanks for the reply,
I've tried your method but the fetchLayoutByFriendlyURL method always returns null so I'm stuck. Is the /portlet-b-page-friendly-url argument a string containing the name of the jsp that I'm trying to use but it always returns null.
In this case the name of the jsp is viewOrder so in that field I wrote "/viewOrder.jsp".
I even tried other alternatives like "view.jsp" or "/view.jsp" thinking that it was because the view.jsp is present in every portlet that we've wrote and I wanted to rule out the possibility that the method couldn't find the jsp from another portlet but it still didn't work.
​​​​​​​What am I missing?
thumbnail
krishna patel, modified 4 Years ago.

RE: Links between portlets

New Member Posts: 14 Join Date: 5/21/18 Recent Posts
Simone de Blasiis:

First of all thanks for the reply,
I've tried your method but the fetchLayoutByFriendlyURL method always returns null so I'm stuck. Is the /portlet-b-page-friendly-url argument a string containing the name of the jsp that I'm trying to use but it always returns null.
In this case the name of the jsp is viewOrder so in that field I wrote "/viewOrder.jsp".
I even tried other alternatives like "view.jsp" or "/view.jsp" thinking that it was because the view.jsp is present in every portlet that we've wrote and I wanted to rule out the possibility that the method couldn't find the jsp from another portlet but it still didn't work.
​​​​​​​What am I missing?


Check the "layout" table in your database. It is a Liferay table and it contains all the Liferay pages data which you have created from the admin control panel. you can look for a public/private page in which you have imported portlet_B. this table contains a column with the name "friendlyurl".  this friendly URL will use to fetch layout instead of your JSP file.