JSF - 关于生命周期的另一个问题
今天我想了解 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上以下内容正在幕后发生(这里,
输入
是UIInput
和request
是HttpServletRequest
):因此,如果没有请求参数,它们将保持不变。它们不会被设置为 null 并保持默认值。
在第二阶段基本上也会发生以下情况(这里,
命令
是UICommand
,request
是HttpServletRequest
和ActionEvent
是ActionEvent
):然后,在调用应用程序阶段,将调用为特定阶段排队的所有事件。
在此阶段,JSF 遍历组件树,所有组件都将被编码(将调用
渲染器
,默认为 HTML 渲染器)。在编码期间,仅从模型中获取值。视图本身不会更新。 基本上:Basically the following is happening under the covers (here,
input
isUIInput
andrequest
isHttpServletRequest
):So, they will be untouched if there's no request parameter. They won't be set with
null
and just kept default.During 2nd phase basically the following will also happen (here,
command
isUICommand
,request
isHttpServletRequest
andActionEvent
isActionEvent
):Then, during invoke application phase, all events which are queued for the particular phase will be invoked.
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: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.
另一篇关于 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