【发布时间】:2012-07-04 14:24:43
【问题描述】:
我正在使用 Liferay 6 进行门户开发。
作者通过Liferay Developer Guide解释说,Portlet 执行分为两个阶段
- 行动阶段
- 渲染阶段
public class DateTimePortlet extends GenericPortlet
{
public void doView(RenderRequest req, RenderResponse res) throws IOException, PortletException
{
Object actionAttribute = req.getAttribute("datetime");
res.getWriter().println("Date Time:" + (actionAttribute != null ? actionAttribute :"Unavailable"));
res.getWriter().println("<BR/>");
PortletURL u = res.createActionURL();
res.getWriter().println("<A href=" + u + ">Trigger an action.");
res.getWriter().close();
}
public void processAction(ActionRequest req, ActionResponse res) throws PortletException
{
req.setAttribute("datetime",new Date());
}
}
我的理解是doView方法被称为“Render Phase”,processAction方法被称为“Action Phase”。
如果页面上显示了 5 个 portlet,则每次页面刷新都会执行“渲染阶段”(即 doView 方法中的代码)。
如果我是正确的,请告诉我。
【问题讨论】: