Foros de discusión

Adding and removing portlets from another one

Julien S, modificado hace 13 años.

Adding and removing portlets from another one

New Member Mensajes: 15 Fecha de incorporación: 21/12/10 Mensajes recientes
Hello folks

Strangly, I didn't find any tips about that neither on the net nor the forum.
I have a portlet, in which I list all the portlets available for the user, with checkboxes in front of each one.
The user may be able to check them, and those who aren't are removed from the page (Just remove, the user may be able to add them later from the portlet), the other are added if not already there.

And my problem is : How can I add and remove the unchecked portlets on a page? I can get the id/displayName/anything you want, but I don't know what to use to do that.

PortletLocalServiceUtil.updatePortlet isn't useful, because it disable portlets.

[EDIT] Oh, and I'm on Liferay 6.0.5, by the way
thumbnail
Pranay R Patadiya, modificado hace 13 años.

RE: Adding and removing portlets from another one (Respuesta)

Regular Member Mensajes: 177 Fecha de incorporación: 23/02/10 Mensajes recientes
Hi,

First of all let me know your LR version.

I think you need to add portlets.

For that you should use:

layout = LayoutLocalServiceUtil.addLayout(
						PortalUtil.getUserId(actionRequest), organization.getGroup().getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
						"Home", "Home",
						StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/"+friendlyURL);
				  
				layout.setThemeId(themeId);	
				  LayoutTypePortlet layoutTypePortlet =
						(LayoutTypePortlet)layout.getLayoutType();
				  		  layoutTypePortlet.setLayoutTemplateId(
							0, defaultLayoutId, false);
	String portletIds = defaultPortletId;
					String[] servicePortlet = StringUtil.split(servicePortletId);
					String[] portletIdsArray = StringUtil.split(portletIds);				 
					layoutTypePortlet.addPortletIds(
						0, portletIdsArray, columnId, false);
					 
					layoutTypePortlet.addPortletIds(
							0, servicePortlet, servicePortletColumnId, false);
				 
					LayoutLocalServiceUtil.updateLayout(
							layout.getGroupId(), false, layout.getLayoutId(),
							layout.getTypeSettings());
					Group group = layout.getGroup();
					  group.setFriendlyURL("/home");



Thanks,
Pranay Patadiya
Julien S, modificado hace 13 años.

RE: Adding and removing portlets from another one

New Member Mensajes: 15 Fecha de incorporación: 21/12/10 Mensajes recientes
Hi Pranay, thanks for your quick help!

I don't understand the line
layoutTypePortlet.setLayoutTemplateId(0, defaultLayoutId, false);


Is it really useful? Where does the defaultLayoutId come from? Is it the layoutId?
Julien S, modificado hace 13 años.

RE: Adding and removing portlets from another one

New Member Mensajes: 15 Fecha de incorporación: 21/12/10 Mensajes recientes
But it seems to work!

Without the
layoutTypePortlet.setLayoutTemplateId
, though..

But anyway, that works, THANK YOU