JSF - 关于生命周期的另一个问题

发布于 2024-10-05 13:17:51 字数 663 浏览 4 评论 0原文

今天我想了解 JSF 生命周期的一些功能。让我开始:

1 - 第 2 阶段:应用请求值 - 在此阶段,视图中的每个组件将在请求中搜索其值并为其设置新值

嗯,好吧。因此,视图将根据前面的 Beans 参数来构建。之后,有一个使用请求值生成的部分视图。 (对吧?稍后3°阶段再进行比较)。但是,例如,如果在创建最后一个视图期间请求列表中的值不存在?值将为空?

2 - 阶段 5:调用应用程序 - 一旦请求的所有值已成功设置到支持 bean,将处理在应用请求值阶段排队的操作事件。在我们的例子中,提交按钮操作方法。

这根本不清楚。此时,我(在 bean 上)已经从上一阶段更新了值(如果验证和应用请求没有失败)。好吧,现在会发生什么?这意味着在应用请求值阶段排队的操作事件将被处理?这意味着,例如,如果操作是提交,那么该过程就完成了?这就是为什么 ajax 调用如果不在 2° 阶段渲染就会失败?或者哪里失败了?

3 - 第 6 阶段:渲染响应 - 在这个阶段,组件树将被渲染到客户端。

这意味着服务器上的视图是通过使用更新的 bean 值来更新的?并且,在此之后,HTML 代码是从该视图创建的?或者只是制作 HTML 代码并保存视图状态?

希望你能帮助我:)

Today I'd like to know some features on the JSF Lifecycle. Let me start :

1 - Phase 2:Apply request Values - During this phase,each component in the view will search for its values in the request and set the new values to them

Uhm, ok nice. So, the View will be built due to the previous Beans parameters. After, there is a partial View, generated with the request values. (Right? Later, in the 3° phase, they will be compared) . But, for example, if a values in the request list is absent during the creation of this last view? Values will be null?

2 - Phase 5: Invoke Application - Once all the values of the request has been successfully set to the backing bean the action events queued during the apply request values phase will be processed. In our case the submit buttons action method .

This is not clear at all. At this moment i have (on the beans) the values updated from the previous Phase (If the validation and the apply request aren't failed). Ok, so now what happens? What means the action events queued during the apply request values phase will be processed? It means that, for example, if the action is Submit the process is finished? That's why an ajax call, if not rendered in the 2° phase, will fail? Or where it fails?

3 - Phase 6: Render response - In this phase the component tree will be rendered to the client.

It means that the View on the server is updated by using the updated bean values? And, after this, the HTML code is created from this View? Or just it made the HTML code and save the View status?

Hope you can help me :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疾风者 2024-10-12 13:17:51

阶段 2:应用请求值 - 在此阶段,视图中的每个组件将在请求中搜索其值并为其设置新值

嗯,好的,不错。因此,视图将根据前面的 Beans 参数来构建。之后,有一个使用请求值生成的部分视图。 (对吧?稍后3°阶段再进行比较)。但是,例如,如果在创建最后一个视图期间请求列表中的值不存在?值将为空?

基本上以下内容正在幕后发生(这里,输入UIInputrequestHttpServletRequest):

if (input.isRendered()) {
    String value = request.getParameter(input.getClientId());
    if (value != null) {
        input.setSubmittedValue(value);
    }
}

因此,如果没有请求参数,它们将保持不变。它们不会被设置为 null 并保持默认值。


阶段 5:调用应用程序 - 一旦请求的所有值都已成功设置到支持 bean,则将处理在应用请求值阶段排队的操作事件。在我们的例子中,提交按钮操作方法。

这根本就不清楚。此时,我(在 bean 上)已经从上一阶段更新了值(如果验证和应用请求没有失败)。好吧,现在会发生什么?这意味着在应用请求值阶段排队的操作事件将被处理?这意味着,例如,如果操作是“提交”,则过程是否已完成?这就是为什么 ajax 调用如果不在 2° 阶段渲染就会失败?或者哪里失败了?

在第二阶段基本上也会发生以下情况(这里,命令UICommandrequestHttpServletRequestActionEventActionEvent ):

if (command.isRendered()) {
    String value = request.getParameter(command.getClientId());
    if (value != null) {
        command.queueEvent(new ActionEvent(command)); // Queue for INVOKE_ACTION.
    }
}

然后,在调用应用程序阶段,将调用为特定阶段排队的所有事件。


阶段 6:渲染响应 - 在此阶段,组件树将渲染给客户端。

这意味着服务器上的View是使用更新后的bean值进行更新的?并且,在此之后,HTML 代码是从该视图创建的?或者只是制作 HTML 代码并保存视图状态?

在此阶段,JSF 遍历组件树,所有组件都将被编码(将调用 渲染器,默认为 HTML 渲染器)。在编码期间,仅从模型中获取值。视图本身不会更新。 基本上

facesContext.getViewRoot().encodeAll();

Phase 2:Apply request Values - During this phase,each component in the view will search for its values in the request and set the new values to them

Uhm, ok nice. So, the View will be built due to the previous Beans parameters. After, there is a partial View, generated with the request values. (Right? Later, in the 3° phase, they will be compared) . But, for example, if a values in the request list is absent during the creation of this last view? Values will be null?

Basically the following is happening under the covers (here, input is UIInput and request is HttpServletRequest):

if (input.isRendered()) {
    String value = request.getParameter(input.getClientId());
    if (value != null) {
        input.setSubmittedValue(value);
    }
}

So, they will be untouched if there's no request parameter. They won't be set with null and just kept default.


Phase 5: Invoke Application - Once all the values of the request has been successfully set to the backing bean the action events queued during the apply request values phase will be processed. In our case the submit buttons action method .

This is not clear at all. At this moment i have (on the beans) the values updated from the previous Phase (If the validation and the apply request aren't failed). Ok, so now what happens? What means the action events queued during the apply request values phase will be processed? It means that, for example, if the action is Submit the process is finished? That's why an ajax call, if not rendered in the 2° phase, will fail? Or where it fails?

During 2nd phase basically the following will also happen (here, command is UICommand, request is HttpServletRequest and ActionEvent is ActionEvent):

if (command.isRendered()) {
    String value = request.getParameter(command.getClientId());
    if (value != null) {
        command.queueEvent(new ActionEvent(command)); // Queue for INVOKE_ACTION.
    }
}

Then, during invoke application phase, all events which are queued for the particular phase will be invoked.


Phase 6: Render response - In this phase the component tree will be rendered to the client.

It means that the View on the server is updated by using the updated bean values? And, after this, the HTML code is created from this View? Or just it made the HTML code and save the View status?

During this phase JSF walks through the component tree and all components will be encoded (will invoke the Renderer of all components, by default a HTML renderer). During encoding, the values will just be obtained from the model. The view itself won't be updated. Basically:

facesContext.getViewRoot().encodeAll();
独孤求败 2024-10-12 13:17:51

1 - 第 2 阶段:应用请求值

此阶段与支持 bean 无关。在这里,我们只是处理请求参数,并尝试将它们“链接”到视图中的组件。在Apply Request阶段,这些HTTP请求参数在注入到实际的bean之前需要进行转换和验证。

2 - 阶段 5:调用应用程序

在 JSF 中,ActionEvents 由 ActionListener 处理。单击该按钮时,将引发一个 ActionEvent 并排队等待稍后阶段处理。 JSF 提供了一个默认的 Actionlistener,它拾取此 ActionEvent 并在处理应用程序阶段对其进行处理。

默认 ActionListener 的实现方式是计算 EL 表达式,并使用结果将其传递给导航监听器。因此,您认为理所当然的事情(按下按钮会执行操作属性中的 EL 表达式并转发到另一个页面)实际上是使用 ActionListener 在内部处理的。

3 - 第 6 阶段:渲染响应 -

JSF 视图是组件树和所有值绑定的内部表示。实际的 HTML 表示由 ViewHandler 处理。

1 - Phase 2:Apply request Values

This phase has nothing to do with the backing bean. Here, we just process the request parameters, and try to "link them" to a component in the view. During the Apply Request phase, these HTTP request parameters need to be converted and validated before they are injected into the actual bean.

2 - Phase 5: Invoke Application

In JSF, ActionEvents are handled by ActionListeners. When clicking the button, an ActionEvent is raised and queued to be processed at a later phase. A default Actionlistener is provided by JSF that picks up this ActionEvent and processes it in the Process Application Phase.

The Default ActionListener is implemented in such a way that it evaluates the EL expression, and uses the outcome to pass it on to a navigationlistener. So what you take for granted (pressing a button executes the EL expression in the action attribute and forwards to another page) is actually handled internally using an ActionListener.

3 - Phase 6: Render response -

A JSF view is an internal representation of the component tree and all value bindings. The actual HTML representation is handled by the ViewHandler.

深海不蓝 2024-10-12 13:17:51

另一篇关于 JSF 生命周期的优秀文章可以在以下位置找到:
http://palkonyves.blogspot.com.br /2013/08/demistifying-jsf-21-lifecycle-mojarra.html

Another excelent article about JSF lifecycle can be found at:
http://palkonyves.blogspot.com.br/2013/08/demistifying-jsf-21-lifecycle-mojarra.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文