深入浅出Liferay Portal (7)

深入浅出Liferay Portal (7)
 

如何在portal中增加一个portlet (非content_portlet)。

通过分析知道,在Add Content中点击某个portlet的add按钮后,服务器会收到一个/c/portal/update_layout...的请求(这里与生成 Add Content Portlet有区别,在前面文章中提到,那时的请求是一个/c/portal/render_portlet...),服务器在收到请求后前面的步骤同上面分析add content portlet的过程一样。

PortalRequestProcess.process()

String path = processPath(request, response);
//这里path = “/portal/update_layout”.

ActionMapping mapping = processMapping(request, response, path);
//这里找到在struts-config.xml中定义的关于上面path的mapping.

Action action = processActionCreate(request, response, mapping);
//这里生成了UpdateLayoutAction.

ActionForward forward = processActionPerform(request, response, action, form, mapping);

processForwardConfig(request, response, forward);

在struts-config.xml中有定义:
<action path="/portal/update_layout" type="com.liferay.portal.action.UpdateLayoutAction" />

UpdateLayoutAction.execute()

LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

String cmd = ParamUtil.getString(req, Constants.CMD);

String portletId = ParamUtil.getString(req, "p_p_id");

if (cmd.equals(Constants.ADD))
{  portletId = layoutTypePortlet.addPortletId(userId, portletId); }
else if (cmd.equals(Constants.DELETE)) { layoutTypePortlet.removePortletId(portletId); }
else if (cmd.equals("drag")) { }
else if (cmd.equals("minimize")) { }
else if (cmd.equals("move")) { layoutTypePortlet.movePortletId(userId, portletId, columnId, columnPos); }
else if (cmd.equals("template")) { }

if (ParamUtil.getBoolen(req, "refresh")) {}
else {
  if (cmd.equals(Constants.ADD) && (portletId != null)) {
  Action renderPortletAction = (Action)InstancePool.get(RenderPortletAction.class.getName());
  renderPortletAction.execute(mapping, form, dynamicReq, res);
}

因为cmd=add,所以调用LayoutTypePortlet.addPortletId()来将portletId加入到Layout中,而且最后调用RenderPortletAction.execute()来将这个portlet最终render出来,具体过程如上面关于content portlet的分析。

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2177387

你可能感兴趣的:(深入浅出Liferay Portal (7))