Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Karthik Baskaran
Create portlets on demand
August 26, 2012 6:37 AM
Answer

Karthik Baskaran

Rank: Junior Member

Posts: 32

Join Date: May 3, 2012

Recent Posts

Hi All,

I have a requirement to create dynamic portlets on demand. The custom portlet that was developed has a list of hyperlinks and on clicking on each of these hyperlinks, i need to create dynamic portlets and add to the page at runtime. I should also be able to remove the unused portlets and add them whenever required. If there a way to accomplish this in liferay. If not what are other alternatives to accomplish this requirement.

Thanks
Karthik
Hitoshi Ozawa
RE: Create portlets on demand
August 26, 2012 4:21 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Liferay does this from their Add menu.

Following thread may help you.
http://www.liferay.com/community/forums/-/message_boards/message/7277551
Karthik Baskaran
RE: Create portlets on demand
August 26, 2012 10:12 PM
Answer

Karthik Baskaran

Rank: Junior Member

Posts: 32

Join Date: May 3, 2012

Recent Posts

Hi,

Based on the URL that was suggested, i have added the below piece of code in my processAction() method, just before setting the portlet mode to VIEW. I am not getting any exceptions and also the portlet is not getting added to the page. Please guide me.

1String friendlyURL = "/my-list";
2Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(12402, true, friendlyURL);
3                String typeSettings = StringPool.BLANK;
4                typeSettings += "column-1=applistportlet" + "\n";
5                layout.setTypeSettings(typeSettings);
6                LayoutLocalServiceUtil.updateLayout(layout.getGroupId(),
7                        layout.isPrivateLayout(), layout.getLayoutId(),
8                        layout.getTypeSettings());


Thanks
Karthik
Hitoshi Ozawa
RE: Create portlets on demand
August 27, 2012 12:07 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

So where is the code to add portlet to the layout? I think you'll only looking at a post to update the layout and missed reading the post on adding portlet to the layout.
LayoutTypePortlet.addPortletId

http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/model/LayoutTypePortlet.html
Karthik Baskaran
RE: Create portlets on demand
August 27, 2012 3:13 AM
Answer

Karthik Baskaran

Rank: Junior Member

Posts: 32

Join Date: May 3, 2012

Recent Posts

Hi,

Yes, i missed the code for adding portlet into the layout. I am now able to add portlets to the page based on my selection from another portlet. But the portlets are no visible unless i click on the page link again (which causes the page to refresh again). Is there any extra setting that needs to be done to make these dynamic portlets visible without refreshing the page explicitly?

The scenario is, when i add a portlet for the first time, the portlet is not visible in page. On adding another portlet to the page, this time i am able to view the first portlet that was added and not able to view the second (recently added) portlet. In order to view both portlets that are loaded dynamically, i have to refresh the page explicitly ! Any pointers to solve this behaviour ?


Thanks
Karthik
Karthik Baskaran
RE: Create portlets on demand
August 27, 2012 10:17 PM
Answer

Karthik Baskaran

Rank: Junior Member

Posts: 32

Join Date: May 3, 2012

Recent Posts

Hi All,

Is there any solution / workaround to overcome this scenario ?

Thanks
Karthik
Karthik Baskaran
RE: Create portlets on demand
August 29, 2012 11:52 PM
Answer

Karthik Baskaran

Rank: Junior Member

Posts: 32

Join Date: May 3, 2012

Recent Posts

Hi All,

I was able to solve using the below code...

1ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
2companyId = themeDisplay.getCompanyId();
3Layout layout = (Layout) actionRequest.getAttribute(WebKeys.LAYOUT);
4LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
5long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
6int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
7String iframePortletId = layoutTypePortlet.addPortletId(themeDisplay.getUserId(), PortletKeys.IFRAME, "column-2", 0);
8PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, layout.getPlid(), iframePortletId, prefs);


Thanks
Karthik