了解动作阶段和渲染阶段的执行 [英] Understanding the execution of Action Phase and Render Phase
问题描述
我正在使用Liferay 6进行门户开发.
通过阅读《 Liferay开发人员指南》 ,作者解释说: 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
方法被称为"渲染阶段",而processAction
方法被称为"动作阶段".
如果页面上显示5个portlet,则每次页面刷新都会执行渲染阶段"(即doView
方法中的代码).
请告诉我我是否正确.
是的,正确的:最大. 1个Portlet处理每个请求的操作,但是页面上的所有Portlet都将运行一个渲染请求(除非输出被缓存,但让我们放下这个相当高级的内容)
仅完成渲染后,对请求的处理也可能为0(这是通常在portlet上执行的最常见的操作.在此阶段,您必须(并且不能)更改任何状态.)>
在执行操作之后,可以触发事件阶段(请参阅Port-Portlet通信,IPC),该阶段可以在任意数量的Portlet上执行.
如果您不希望重新加载整个页面,则必须进入资源阶段,在此阶段您可以处理AJAX调用并提供各种不同的资源,而Portlet所要使用的常规页面片段除外.服务.
I am using Liferay 6 for the Portal Development .
By going through Liferay Developer Guide the author explains that there are Two phases of Portlet Execution
- Action Phase
- Render Phase
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());
}
}
My understanding is that the doView
method is known as "Render Phase" and the processAction
Method is known as "Action Phase".
And if there are 5 portlets displayed on a page, the "Render Phase" (That is the code inside the doView
Method) is executed for every Page refresh.
Please let me know if i am correct.
Yes, correct: There's max. 1 portlet handling an action per request, but all of the portlets on the page will have a render request running (unless the output is cached, but let's put aside this rather advanced stuff)
There can also be 0 action handling on a request, when just rendering is done (this is the most common operation typically executed on a portlet. You must (and can) not change any state in this phase.).
Following an Action, the event phase can be triggered (see Inter-Portlet-Communication, IPC) that can be executed on any number of portlets.
If you don't want a full page reload, you'll have to look into the resource-phase where you can handle AJAX calls and serve all kinds of different resources other than the usual page fragments that a portlet is meant to serve.
这篇关于了解动作阶段和渲染阶段的执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!