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

查看:63
本文介绍了应该将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应用程序中的部分状态保存有关的一般性缺陷时,真的不能用另一种方法解决/解决.部分状态保存在总体性能和内存使用方面具有主要优势.另请参见

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中,当您绑定标签处理程序的任何属性时,围绕部分状态保存的问题的根本原因将会显现出来(由于缺少<标签上的c0>属性(例如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天全站免登陆