Call another portlet programatically

Purpose: to call IOPortlet when a new workflow is started.

Created the “TestlaunchingUI” portlet to launch “TestIcePush” portlet, but no luck so far.

Try to add a porlet with the id “TestrefresherApplicationportlet_WAR_TestRefresher”

This succeeded:

TestrefresherApplicationportlet_WAR_TestRefresher

column-1

ThemeDisplay themeDisplay= (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
String columnId = request.getParameter(porletColumnId);
Layout layout = themeDisplay.getLayout();
if(layout == null)
{
Notification.show(“layout is nulll: ” + request.toString() + ” \n “, Type.ERROR_MESSAGE);
return;
}
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
try {
String portletInstanceId = layoutTypePortlet.addPortletId(0, porletid, columnId, -1, false);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
} catch (PortalException e) {} catch (SystemException e) {}

–> make sure to check themedisplay is not null.

Other problem: have to refresh to show the portlet —> this is not nice.

This one has solution so that no need to refresh: https://www.liferay.com/community/forums/-/message_boards/message/2569244

or here https://www.liferay.com/community/forums/-/message_boards/message/15480775

Another issue is how to delete a portlet after finishing.

One solution: after adding one portlet, refresh page

Page.getCurrent().getJavaScript().execute(“location.reload(true);”);

Might be better if I can just refresh part of the page, but this is good enough.

add a new page:

long companyId = _themeDisplay.getCompanyId();
long userId = _themeDisplay.getUserId();
long groupid = _themeDisplay.getLayout().getGroupId();
long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
ServiceContext serviceContext = new ServiceContext();
Layout layout = LayoutLocalServiceUtil.addLayout(userId, //userId
groupid, //groupId
false, //privateLayout
0, //parentLayoutId
pageName, //name
pageName, //title
“This is a new page”, //description
“portlet”, //type
false, //hidden
“/” + pageName, //friendlyURL
serviceContext);

//and refresh of course

Since Vaadin IPC liferay is not working between pages, try this to pass arguments:

PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, layout.getPlid(), porletid);
prefs.setValue(“param1”, “value1”);
prefs.setValue(“param2”, “value2”);
PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, layout.getPlid(), porletid, prefs);
prefs.store();

This works, but notice that the portletid is the portlet INSTANCE ID, not the portlet id. so correct code:

PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, layout.getPlid(), portletInstanceId);
prefs.setValue(“param1”, “This is param1”);
prefs.setValue(“param2”, “This is param2222222222”);
prefs.store();

 

About slump

Dr Slump ... :D.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: