Understanding the execution of Action Phase and Render Phase

青春壹個敷衍的年華 提交于 2019-12-06 14:58:26

问题


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

  1. Action Phase
  2. 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.


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!