JSF 2.0部分状态保存似乎不起作用 [英] JSF 2.0 partial state saving does not seem to work

查看:95
本文介绍了JSF 2.0部分状态保存似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估在高流量网站中使用JSF的可能性.有人告诉我,在JSF 2.0中,组件树没有存储在会话中,并且一旦修改了组件树,就仅存储增量.

I am evaluating the possibility of using JSF in a high-traffic website. I am told that in JSF 2.0 the component tree is not stored in the session, and that only deltas are stored once the component tree is modified.

这是我正在查看的页面:

Here is the page I am viewing:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html">
    <body>
        <h:form>
            hello, world
        </h:form>
    </body>
</html>

每次查看此页面时,将近1K分配给该会话.如果删除<form>标记,则会话中将不存储任何内容.

Every time I view this page, nearly 1K is allocated to the session. If I remove the <form> tag, nothing is stored in the session.

您知道为什么将组件树存储在会话中吗?我认为这将根据回发请求进行计算.

Any idea why the component tree is being stored in the session? I would think that this would be computed on the postback request.

推荐答案

部分状态保存并不意味着该状态不会保存在会话中.这仅意味着将保存组件树状态的 part 而不是 entire 组件树状态.部分保存状态的关键思想是不会保存客户端在后续请求中不会更改的组件的状态.而是通过在还原视图期间在服务器端重新执行该视图来获得的.仅保存对客户端更改敏感的组件状态(表单,输入,按钮等).您在会话中看到的1K就是部分状态本身.

Partial state saving does not mean that the state won't be saved in the session. It only means that a part of the component tree state will be saved instead of the entire component tree state. The key idea of partial state saving is that the state of components which wouldn't be changed by the client side in the subsequent request won't be saved. Instead, it is obtained by re-executing the view on the server side during restore view. Only the component state which is sensitive to changes by the client (forms, inputs, buttons, etc) will be saved. The 1K which you see in session is the partial state itself.

要自己进行测试,请通过web.xml中的以下context-param开启和关闭状态:

To test it yourself, toggle the state on and off by the following context-param in web.xml:

<context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
</context-param>

当设置为false时,您会看到大小增加,这意味着将保存整个组件树.

You'll see that the size increases when the setting is false, which means that the entire component tree is been saved instead.

它存储在会话中,因为这是Servlet API唯一提供的,它的作用域大于请求作用域.在请求范围内存储将没有任何价值,因为在后续请求中将不再可用. Servlet API没有像JSF那样具有视图范围的概念(顺便说一句,它间接地使用了会话范围,基本上,视图状态是组件树状态).

It is stored in session because that's the only provided by the Servlet API which has a larger scope than the request scope. Storing in request scope would have no value since it wouldn't be available anymore on the subsequent request. The Servlet API has no notion of the view scope like as JSF has (which is under the covers indirectly using the session scope by the way, basically, the view state is the component tree state).

删除表单后,您实际上再也看不到它了,因为实际上没有任何其他内容可供客户更改(即不会有回发).那时保存状态是没有意义的.此外,没有任何东西可以将保存状态的键作为隐藏的输入字段(名称为javax.faces.ViewState)传递.

You indeed don't see it anymore when you remove the form since there's actually nothing left which the client could change (i.e. there would be no postback). It would not make sense to save the state then. Besides, there would be nothing to pass the key of the saved state as a hidden input field (with the name javax.faces.ViewState).

  • What's new in JSF 2.0? - State saving
  • What's the view build time?
  • Why JSF saves the state of UI components on server?

这篇关于JSF 2.0部分状态保存似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆