如何在portal中增加一個portlet (非content_portlet)。
通過分析知道,在Add Content中點擊某個portlet的add按鈕后,服務(wù)器會收到一個/c/portal/update_layout...的請求(這里與生成 Add Content Portlet有區(qū)別,在前面文章中提到,那時的請求是一個/c/portal/render_portlet...),服務(wù)器在收到請求后前面的步驟同上面分析add content portlet的過程一樣。
PortalRequestProcess.process()
String path = processPath(request, response);
//這里path = “/portal/update_layout”.
ActionMapping mapping = processMapping(request, response, path);
//這里找到在struts-config.xml中定義的關(guān)于上面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,所以調(diào)用LayoutTypePortlet.addPortletId()來將portletId加入到Layout中,而且最后調(diào)用RenderPortletAction.execute()來將這個portlet最終render出來,具體過程如上面關(guān)于content portlet的分析。
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2177387