我一直致力于在MVCPortlet
控制器中编程创建Liferay actionUrls。
到目前为止,我已成功设法创建另一个portlet的动作的工作链接,
使用此代码放置在另一页(Liferay术语中为Layout
)中:
LiferayPortletResponse rr = PortalUtil.getLiferayPortletResponse( response);
Layout layout = ... // I manage to get the correct one using LayoutLocalServiceUtil
LiferayPortletURL ddUrl = rr.createActionURL("portlet_WAR_name") ;
if(Validator.isNotNull(layout)){
// Setting info to the other portlet
ddUrl.setPlid(layout.getPlid());
// Setting the action Name
ddUrl.setParameter(ActionRequest.ACTION_NAME, "actionFunctionNameOf_MVCPortlet");
// adding any action-related params
ddUrl.setParameter("someParam1", ...) );
ddUrl.setParameter("someParam2", ...) );
return ddUrl;
}
我的问题是,这不适用于可实例 Portlet。
是否可以添加一些参数,以使此url链接到目标Portlet的-any-
实例?
或者我是否需要知道目标Portlet的instanceId
?如果是,我该如何将其设置为LiferayPortletURL
实例?
Thanx提前,任何帮助都会非常感激
P.S。:我正在使用Liferay 6.1 GA1
答案 0 :(得分:3)
您可以将portletid设置为可实例 portlet ID:
String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
ddUrl.setPortletId(portletId);
答案 1 :(得分:1)
LiferayPortletResponse rr = PortalUtil.getLiferayPortletResponse( response);
// I get the correct layout using LayoutLocalServiceUtil
Layout layout = ... ;
LiferayPortletURL ddUrl = rr.createActionURL("portlet_WAR_name");
if(layout != null) {
// Setting info to the other portlet
ddUrl.setPlid(layout.getPlid());
// Setting the action Name
ddUrl.setParameter(ActionRequest.ACTION_NAME, "actionFunctionNameOf_MVCPortlet");
//Finding the full portletId of the instanceable Portlet
LayoutTypePortlet layoutTypePortlet =
LayoutTypePortletFactoryUtil.create(
LayoutLocalServiceUtil.getFriendlyURLLayout(
themeDisplay.getLayout().getGroupId(),
false, "page_friendly_url")
);
List<String> portletIdList = layoutTypePortlet.getPortletIds();
for(String prtId : portletIdList){
if(prtId.contains("portlet_WAR_name")){
ddUrl.setPortletId(prtId);
}
}
// adding any action-related params
ddUrl.setParameter("someParam1", ...) );
ddUrl.setParameter("someParam2", ...) );
return ddUrl;
}
感谢Tony Rad为setPortletId
上的hint。
我还发现this answer非常有用。