了解动作阶段和渲染阶段的执行

编程入门 行业动态 更新时间:2024-10-25 09:34:07
本文介绍了了解动作阶段和渲染阶段的执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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.

    更多推荐

    了解动作阶段和渲染阶段的执行

    本文发布于:2023-10-07 17:29:13,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1470028.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:阶段   动作

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!