Pages

Saturday, 14 April 2012

Create a link from one portlet which will refresh another portlet and if the other portlet is not available ,it will be appended to the current page dynamically.


Create a link from one portlet  which will refresh another  portlet and if the other portlet is not available ,it will be appended to the current page dynamically.
Create a link in one partlet  which will refresh another portlet in the sament page,even if portlet is not present in the current page.

Are Portal A and Portal B on same page ?
If both are   on same page. And on clicking a link in portlet-A, Portlet-B will be maximized. Actually my intent is to generate link in Portlet-A, which refers to Portlet-B.
Put this code in Portlet-A
add this tag library in ur jsp page(Very important)
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>


<liferay-portlet:renderURL var="linkURL" portletName="Portlet-B_WAR_Portlet-B" windowState="maximized" />
<a href="<%= linkURL%>">link to portlet-B</a>

eg:

I have a custom portlet called "B" and its instance id is "portlet_B_WAR_Bportlet". I removed "portlet_" from the instance id and used remaining thing as portlet name for the link

<liferay-portlet:renderURL var="linkURL"
portletName="B_WAR_Bportlet" windowState="maximized" />
<a href="<%= linkURL%>">link to document library</a>


I tried that. It is works  fine if we use portlet name as B_WAR-Portlet-B_INSTANCE_<instance-id>. And <instance-id> is not the same for every instance created. If someone delete current instance & re instantiate the portlet then it won't be the same.
So can we have any way to get <instance-id> dynamically at run time?
Yes you can.
Then we have to make changes in our liferay-portlet.xml file

Here as we  have a link to portlet-B in ur portlet-A
If portlet-B is present in the current page it will be maximized.. if the Portlet-B is not present in the current page, temporarily Portlet-B will be created with maximized state. once we click on "return on full page" of portle-B , it will be removed from the page and we can see our portlet-A
eg: Just go to control panel if u click on image gallery it  will be instantiated automatically, after you use it .It will  be destroyed automatically.

In liferay-portlet.xml one tag is there
'<add-default-resource>true</add-default-resource>'.
using this we can implement this functionality

What I did is:
1.) Added <add-default-resource>true</add-default-resource> to liferay-portlet.xml file
2.) Added link to  Portlet-A which we want to call other portlet i.e. Portlet-B, without instanceId.

This way the Portlet-B will be open, even though the instance of this portlet is not exist on the page. I had open Portlet-B on the same page which contains Portlet-A.

1 comment: