Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Jay Trivedi
Add Portelt programatically on Layout
19 de marzo de 2013 3:42
Respuesta

Jay Trivedi

Ranking: Regular Member

Mensajes: 107

Fecha de incorporación: 23 de noviembre de 2012

Mensajes recientes

Hey Friends,
I want to programatically add Portlet on Layout.
I tried this

 1
 2/ add a content display portlet
 3// The column id and position (last 2 parameters below) will depend on your layout template
 4String journalPortletId = layoutTypePortlet.addPortletId(userId,
 5                                        PortletKeys.JOURNAL_CONTENT,
 6                                        "column-3",
 7                                        -1);
 8
 9long companyId = themeDisplay.getCompanyId();
10long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
11int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
12
13// Retrieve the portlet preferences for the journal portlet instance just created
14PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId,
15                                        ownerId,
16                                        ownerType,
17                                        layout.getPlid(),
18                                        journalPortletId);
19
20// set desired article id for content display portlet
21prefs.setValue("article-id", "123456");
22prefs.setValue("group-id", String.valueOf(groupId));
23
24// update the portlet preferences
25PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, layout
26                                        .getPlid(), journalPortletId, prefs);


I followed http://www.liferay.com/community/wiki/-/wiki/Main/Programmatically+Create+a+Layout+and+Place+a+Portlet+on+it
But i don't get any output neither i find any updates in ProtletPrefernces and Layout Table.

Let me share some details.
- > I have created Group Programatically.
-> Later i realized that i need to create layout for it.
-> Now the acutal requirement starts i need to add document and library portlet for that particular group to share documents for that group.
-> So i decided to dynamically create a page and set layout for it.[did it successfully]
-> Now i want to add Document and media portlet for that gorup.
-> But i am failing to do it.

Any Suggestions. emoticon
Apoorva Prakash
RE: Add Portelt programatically on Layout
19 de marzo de 2013 3:49
Respuesta

Apoorva Prakash

Ranking: Liferay Master

Mensajes: 659

Fecha de incorporación: 15 de junio de 2010

Mensajes recientes

Jay Trivedi:
Hey Friends,
I want to programatically add Portlet on Layout.
I tried this

 1
 2/ add a content display portlet
 3// The column id and position (last 2 parameters below) will depend on your layout template
 4String journalPortletId = layoutTypePortlet.addPortletId(userId,
 5                                        PortletKeys.JOURNAL_CONTENT,
 6                                        "column-3",
 7                                        -1);
 8
 9long companyId = themeDisplay.getCompanyId();
10long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
11int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
12
13// Retrieve the portlet preferences for the journal portlet instance just created
14PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId,
15                                        ownerId,
16                                        ownerType,
17                                        layout.getPlid(),
18                                        journalPortletId);
19
20// set desired article id for content display portlet
21prefs.setValue("article-id", "123456");
22prefs.setValue("group-id", String.valueOf(groupId));
23
24// update the portlet preferences
25PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, layout
26                                        .getPlid(), journalPortletId, prefs);


I followed http://www.liferay.com/community/wiki/-/wiki/Main/Programmatically+Create+a+Layout+and+Place+a+Portlet+on+it
But i don't get any output neither i find any updates in ProtletPrefernces and Layout Table.

Let me share some details.
- > I have created Group Programatically.
-> Later i realized that i need to create layout for it.
-> Now the acutal requirement starts i need to add document and library portlet for that particular group to share documents for that group.
-> So i decided to dynamically create a page and set layout for it.[did it successfully]
-> Now i want to add Document and media portlet for that gorup.
-> But i am failing to do it.

Any Suggestions. emoticon


Hello Jay,

Have a look on this blog, you may find it useful.

Hope this will help...

Thanks and Regards,
Apoorva Prakash
serena corvino
RE: Add Portelt programatically on Layout
12 de septiembre de 2013 2:08
Respuesta

serena corvino

Ranking: New Member

Mensajes: 2

Fecha de incorporación: 15 de mayo de 2013

Mensajes recientes

Hi,

I also follow the wiki to add JOURNAL_CONTENT to a new layout programmatically.
Everything seems to be correct, but when I open the page the portlet doesn't display any article.
I've tried this 2 solutions but nothing.
1PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, newPage.getPlid(), journalPortletId);
2prefs.setValue("articleId", content.getArticleId());
3prefs.setValue("groupId", String.valueOf(groupId));
4//prefs.setValue("article-id", content.getArticleId());
5//prefs.setValue("group-id", String.valueOf(groupId));

If I debug html/portlet/journal_content/view.jsp the param "articleId" is always null. Any solution?
vasv kumar
RE: Add Portelt programatically on Layout
12 de septiembre de 2013 5:40
Respuesta

vasv kumar

Ranking: Junior Member

Mensajes: 46

Fecha de incorporación: 7 de febrero de 2011

Mensajes recientes

Hi,

prefs.setValue("articleId", content.getArticleId());
prefs.setValue("groupId", String.valueOf(groupId));

The above statements are working.Just now i checked

Thanks
Vissu