2
votes

I have a liferay portlet instance created dynamically and added to the layout programatically as follows

String portletId = objUtil.addPortlet("/prj/reports", "XYZPortlet_WAR_ecpmportlet", "column-2",groupId, "type: " + getSelectedType());

So it adds a portlet to the /reports page.
I want to add a button below the portlet called send to dashboard on clicking the button I want to install this portlet to the user dashboard permanently.

Note: There can any number of portlet instances added to the /reports page.

As you see XYZPortlet is the id of the portlet defined in liferay-portlet.xml, liferay-display.xml which remains same for all the portlets I add to the reports page.

I want to dynamically assign a new Id to the portlet instance and install it permanently to the dashboard layout.

Can anyone please suggest a way to do this?

Thanks

1
What do you have try yet and what fails?Mark
@mark I need to install the portlet instance added to reports page to the users dashboard..Padmanabha Vn
@PadmanabhaVn what do you mean by statement "I want to dynamically assign a new Id to the portlet instance"? Can you please give clarification on that.?Pankaj Kathiriya
@PankajKathiriya .. we have entry for portlet in xml files and we are creating an instance of that portlet and adding it using addPortlet function.. so we want this instance to be given new name and install it permanently to dashboard layout and we want it to be appear in more portlets dropdownPadmanabha Vn

1 Answers

2
votes

Simple get the global portletId and add it to user home page:

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