PARTIAL_STATE_SAVING 应该设置为 false 吗? [英] Should PARTIAL_STATE_SAVING be set to false?

查看:16
本文介绍了PARTIAL_STATE_SAVING 应该设置为 false 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天(2012 年 4 月),MyFaces 和 Mojarra 的 JSF 2.1 实现似乎在部分状态保存方面存在缺陷,并且 PARTIAL_STATE_SAVING 应该设置为 false.

It seems that today (April 2012), both MyFaces and Mojarra's JSF 2.1 implementations have defects around partial state saving and that PARTIAL_STATE_SAVING should be set to false.

这是真的吗?

推荐答案

是否应该将 PARTIAL_STATE_SAVING 设置为 false?

当您遇到与 Web 应用程序中的部分状态保存相关的一般缺陷时,确实无法通过其他方式解决/变通.部分状态保存在整体性能和内存使用方面具有主要优势.另见 为什么 JSF 将 UI 组件的状态保存在服务器上?

Only when you encounter a general defect related to partial state saving in your webapp which can really not be solved/workarounded the other way. Partial state saving has namely major advantages as to overall performance and memory usage. See also Why JSF saves the state of UI components on server?

我不能 100% 可靠地为 MyFaces 说话,但在 Mojarra 中,当您绑定标签处理程序的任何属性时,部分状态保存问题的根本原因就会显现出来(标签处理程序可以通过缺少 rendered 属性(例如 JSTL 标记)到视图范围的 bean,或者当您绑定 JSF 的 idbinding 属性时组件到视图作用域 bean(即在构建/恢复视图期间解析这些属性).

I can't 100% reliably speak for MyFaces, but in Mojarra the root cause of problems around partial state saving will manifest when you're binding any attribute of a tag handler (tag handlers are recognizeable by the lack of the rendered attribute on the tag such as JSTL tags) to a view scoped bean, or when you're binding the id or binding attribute of a JSF component to a view scoped bean (those attributes are namely resolved during building/restoring the view).

此问题是由 JSF 问题 1492 中所述的鸡-蛋问题引起的和 JSF 规范问题 787:启用部分状态保存后,视图范围的 bean 被存储在局部视图状态.因此,要提取视图范围的 bean,必须恢复部分视图状态.在恢复(构建)视图期间,将评估所有上述属性中的 EL.但是,由于此时没有视图范围的 bean 实例可用,因此将创建一个全新的实例.但是,这会将其所有属性设置为默认值!在恢复视图并取回原始视图范围的 bean 后,它们将被放回视图范围,覆盖在恢复视图期间创建的(临时)实例.但是这些属性的EL表达式已经基于完全不同的实例进行了评估,无法恢复.

This problem is caused by a chicken-egg issue as described in JSF issue 1492 and JSF spec issue 787: with partial state saving enabled, the view scoped beans were stored in the partial view state. So to extract view scoped beans, the partial view state has to be restored. During restoring (building) the view, the EL in all of the aforementioned attributes will be evaluated. However, since there's no view scoped bean instance available at that moment, a brand new one instance will be created. This will however have all its properties set to default! After restoring the view and getting the original view scoped beans back, they will be put back in the view scope, overridding the (temporary) instances created during restoring the view. But the EL expressions of those attributes are already been evaluated based on a completely different instance and can't be restored.

从 Mojarra 2.1.18 和 2.2.0 开始,通过在会话中存储视图范围的 bean,这个先有鸡的问题得到了解决.如果由于某种原因无法升级,那么确实可以通过将 javax.faces.PARTIAL_STATE_SAVING 设置为 false 来禁用部分状态保存来解决这个问题.另一种选择是完全将上述属性绑定到视图范围的 bean,而是寻找替代解决方案.

This chicken-egg issue is solved since Mojarra 2.1.18 and 2.2.0 by storing view scoped beans in session. If you can't upgrade for some reason, then this can indeed be solved by disabling the partial state saving by setting javax.faces.PARTIAL_STATE_SAVING to false. An alternative is to just not bind the aforementioned attributes to a view scoped bean at all, but look for an alternative solution.

您也可以改为设置 javax.faces.FULL_STATE_SAVING_VIEW_IDS.这允许您指定需要关闭部分状态保存的所有视图 ID 的逗号分隔列表:

You could also set the javax.faces.FULL_STATE_SAVING_VIEW_IDS instead. This allows you to specify a comma separated list of all view IDs for which partial state saving needs to be turned off:

<context-param>
    <param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name>
    <param-value>/some.xhtml,/other.xhtml</param-value>
</context-param>

这使您可以尽可能多地从部分状态保存中受益,并仅对部分状态保存相关问题无法真正修复的视图子集关闭它.

This allows you to benefit from partial state saving as much as possible and turn it off for only a subset of views on which the partial state saving related problems can really not be fixed.

  • Communication in JSF 2.0 - @ViewScoped fails in tag handlers

这篇关于PARTIAL_STATE_SAVING 应该设置为 false 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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