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.
来源:https://stackoverflow.com/questions/11330969/understanding-the-execution-of-action-phase-and-render-phase