Foren

Programatically remove portlets.

R K, geändert vor 13 Jahren.

Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
HI..

I know we can add potlets programatically.But i would like to remove the portlet programatically.

How can i do that ???

Thanks
R K, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
Has no one tried this???

Guys need help !!!
thumbnail
Saranya Sethurajan, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 57 Beitrittsdatum: 08.10.09 Neueste Beiträge
To remove the portlet from the Liferay server, Shut down the server, after that go to Tomcat/webapps/select your <portlet> and delete it.

To delete from Plugins, Go to plugins/portlet/select your <portlet> and delete it.Then, plugins/dist/ select the .war file of your portlet and delete it.
thumbnail
Murat ÇOLAK, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 45 Beitrittsdatum: 28.07.09 Neueste Beiträge
You will write a service first Which is delete the portlet war file from autodeploy directory then Call your service

Or delete portletid from db.

I don't understand what you want
R K, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
HI..

Thanks for the reply.
Unfortunately shutting down the server is not the right option at runtime.
And i would be needing this portlet at later stages also, so i cant delete frm webapps as well.

My requirement is this.

I have 2 portlets (portlet 1 & portlet 2) on my page.

In portlet 1 i also have a link. On the click of the link i want to remove portlet 2 from

that page.

NOTE :Here the user will still be provided with an option to add portlet 2 when ever he wishes. So i wont be able to remove the portlet details from webapps .

Thanks,
RK
thumbnail
KK rajput, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Expert Beiträge: 266 Beitrittsdatum: 10.04.08 Neueste Beiträge
Hi R K,
I don't think it is like removing the portlet . I think it is like hiding and showing portlet on click. I hope this idea will help u.
R K, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
Yeah..tats right..

How can i hide the portlet ???

Thanks,
RK
thumbnail
Suhail Ahmed, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Regular Member Beiträge: 126 Beitrittsdatum: 02.01.08 Neueste Beiträge
HI


This is the sample code you remove the portlet from your layout(or Page),

Try This may Help You


&lt;%@ include file="/html/common/init.jsp" %&gt;

<portlet:defineobjects />




&lt;%

Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);

PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletDisplay.getId());

%&gt;

<c:if test="<%= portletDisplay.isShowCloseIcon() %>">
	<span class="portlet-close">
		- [color=#FF0000]<a href="<%= portletDisplay.getURLClose() %>"><liferay-ui:message key="close" /></a>[/color]
	</span>
</c:if>



on red text click you will close the clicked portlet, if want to close other portlet click of this kindly pass the portlet ID of that portlet.


Thanks

Suhail Ahmed
R K, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
Suhail,

Where do i pass the portlet ID.?
In the sample code, first block is about initialising init.jsp and second is getting the layout and corresponding portlets displayed on the same.
I am not that clear on the third part.Can you kindly explain nd whr should i pass the portlet ID.

Thanks
thumbnail
Suhail Ahmed, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Regular Member Beiträge: 126 Beitrittsdatum: 02.01.08 Neueste Beiträge
R. K,


[color=#FF0000]&lt;%= portletDisplay.getURLClose() %&gt;[/color]


this code only to remove the portlet in which you placed.


if you want to remove another portlet form other portlet, first get the portletId of which portlet you want to remove from the layout.



        if (layoutTypePortlet.hasPortletId(portletId)) {
		deletePortlet = true;
		layoutTypePortlet.removePortletId(userId, portletId);
	}
        
        if (deletePortlet) {
		String rootPortletId = PortletConstants.getRootPortletId(portletId);

		ResourceLocalServiceUtil.deleteResource(
              		layout.getCompanyId(), rootPortletId,
			ResourceConstants.SCOPE_INDIVIDUAL,
			PortletPermissionUtil.getPrimaryKey(
			layout.getPlid(), portletId));
	}

May this Help for You,

Thanks

Suhail Ahmed
R K, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
Thanks for the reply

How can i get the userId ?

I tried request.getAttribute(PortletRequest.USER_INFO) but emoticon

I a not sure as how to get userID ofype LONG.

Thanks
thumbnail
Suhail Ahmed, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Regular Member Beiträge: 126 Beitrittsdatum: 02.01.08 Neueste Beiträge
As ways Wel Come,

you get userId of current user in a various ways, followed


long userId = themeDisplay.getUserId();

OR

long userId = PortalUtil.getUserId(request);






Thanks

Suhail Ahmed
R K, geändert vor 13 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 43 Beitrittsdatum: 24.05.10 Neueste Beiträge
Thanks..

Its working
Jing Guo, geändert vor 11 Jahren.

RE: Programatically remove portlets.

New Member Beiträge: 4 Beitrittsdatum: 24.07.12 Neueste Beiträge
Hey,

I think this is working for non-instanceable portlet, but not for instanceable ones since their portlet Id is something like <porltename>_INSTANCE<instance serial>. I am having problem with it right now, I wonder if you could probably help me out a little bit. Thanks

Jing Guo
Jhansi Rani, geändert vor 12 Jahren.

RE: Programatically remove portlets.

Junior Member Beiträge: 32 Beitrittsdatum: 27.07.11 Neueste Beiträge
Hi Suhail,

I am very new to liferay and using lifery6.0.5.
The code snippet for removing the portlets is very helpful to me .But I struck up with one issue i.e While the reloading the page or refreshing page I need to hide/remove the portlets which are in that page .
Could you please provide the solution.

Regards
Jhansi Rani.
thumbnail
Suhail Ahmed, geändert vor 10 Jahren.

RE: Programatically remove portlets.

Regular Member Beiträge: 126 Beitrittsdatum: 02.01.08 Neueste Beiträge
Hey Yamini,

I did not understand your problem or issue. Kindly elaborate more on this.


Thanks
chandra sekhar, geändert vor 12 Jahren.

RE: Programatically remove portlets.

Regular Member Beiträge: 149 Beitrittsdatum: 07.07.09 Neueste Beiträge
Hi R K,

Can you explain me the how to add the portlets programatically to the Organization pages.

Thanks in advance.

Regards,
Chandrasekhar
thumbnail
Pankaj Kathiriya, geändert vor 12 Jahren.

RE: Programatically remove portlets.

Liferay Master Beiträge: 722 Beitrittsdatum: 05.08.10 Neueste Beiträge
Hi Chandra Shekhar,
If you have layout object that represent pagein place.
Then,You can add portlet to page dynamically by following snippet.

LayoutTypePortlet layoutTypePortlet =(LayoutTypePortlet)layout.getLayoutType();
portletId = layoutTypePortlet.addPortletId(0, portletId, columnId, -1, false);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());



Hope this helps.


Thanks,
Pankaj