Foren
Add portlet programmatically
Long Bao Ly, geändert vor 13 Jahren.
Add portlet programmatically
New Member Beiträge: 14 Beitrittsdatum: 05.11.10 Neueste Beiträge
Hi everyone!
I am using liferay 6.1.2 .I wanna add portlet programtically
This is my code
AddPortletController.java
/*----------------------------------------------------------
Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
long userid=Long.parseLong(request.getRemoteUser());
layoutTypePortlet.addPortletId(userid,portletId,colunmId,-1);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),layout.getLayoutId(), layout.getTypeSettings());
return new ModelAndView("my JSP");
*-------------------------------------------------------------------------/
I call that Controller by using this code in my JSP
<a href='<portlet:renderURL>
<portlet:param name="action" value="AddPortletController"/>
<portlet:param name="link" value="CoreVNITT_WAR_CoreVNIT"/>
</portlet:renderURL>'">Link
</a>
It works when I click the link but the portlet I wanna add only shows up after refreshing my JSP.
I don't quite understand .Please help me out with this problem!!!!
I am using liferay 6.1.2 .I wanna add portlet programtically
This is my code
AddPortletController.java
/*----------------------------------------------------------
Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
long userid=Long.parseLong(request.getRemoteUser());
layoutTypePortlet.addPortletId(userid,portletId,colunmId,-1);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),layout.getLayoutId(), layout.getTypeSettings());
return new ModelAndView("my JSP");
*-------------------------------------------------------------------------/
I call that Controller by using this code in my JSP
<a href='<portlet:renderURL>
<portlet:param name="action" value="AddPortletController"/>
<portlet:param name="link" value="CoreVNITT_WAR_CoreVNIT"/>
</portlet:renderURL>'">Link
</a>
It works when I click the link but the portlet I wanna add only shows up after refreshing my JSP.
I don't quite understand .Please help me out with this problem!!!!
jelmer kuperus, geändert vor 13 Jahren.
RE: Add portlet programmatically
Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
You are adding the portlet in a render method, do it in an action instead, after the action is executed the whole page will be re-rendered and it will work.
Long Bao Ly, geändert vor 13 Jahren.
RE: Add portlet programmatically
New Member Beiträge: 14 Beitrittsdatum: 05.11.10 Neueste Beiträge
Thanks jelmer
I did what you told me and it works.
Hope this topic can help the others
I did what you told me and it works.
Hope this topic can help the others