Fórum

Programatically remove portlets.

R K, modificado 13 Anos atrás.

Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
Has no one tried this???

Guys need help !!!
thumbnail
Saranya Sethurajan, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 57 Data de Entrada: 08/10/09 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 45 Data de Entrada: 28/07/09 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Expert Postagens: 266 Data de Entrada: 10/04/08 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
Yeah..tats right..

How can i hide the portlet ???

Thanks,
RK
thumbnail
Suhail Ahmed, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Regular Member Postagens: 126 Data de Entrada: 02/01/08 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Regular Member Postagens: 126 Data de Entrada: 02/01/08 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Regular Member Postagens: 126 Data de Entrada: 02/01/08 Postagens Recentes
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, modificado 13 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 43 Data de Entrada: 24/05/10 Postagens Recentes
Thanks..

Its working
Jing Guo, modificado 11 Anos atrás.

RE: Programatically remove portlets.

New Member Postagens: 4 Data de Entrada: 24/07/12 Postagens Recentes
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, modificado 12 Anos atrás.

RE: Programatically remove portlets.

Junior Member Postagens: 32 Data de Entrada: 27/07/11 Postagens Recentes
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, modificado 10 Anos atrás.

RE: Programatically remove portlets.

Regular Member Postagens: 126 Data de Entrada: 02/01/08 Postagens Recentes
Hey Yamini,

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


Thanks
chandra sekhar, modificado 12 Anos atrás.

RE: Programatically remove portlets.

Regular Member Postagens: 149 Data de Entrada: 07/07/09 Postagens Recentes
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, modificado 12 Anos atrás.

RE: Programatically remove portlets.

Liferay Master Postagens: 722 Data de Entrada: 05/08/10 Postagens Recentes
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