JSF属性引用范围比目标范围视图短的范围中的对象 [英] JSF Property references object in a scope with shorter lifetime than the target scope view

查看:102
本文介绍了JSF属性引用范围比目标范围视图短的范围中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视角范围内的托管bean,其托管属性绑定到querystring参数. JSF给了我一个熟悉的例外:

I have a view-scoped managed bean with a managed property bound to a querystring parameter. JSF gives me the familiar exception:

javax.faces.FacesException:

javax.faces.FacesException:

Property reset references object in a scope with shorter lifetime than the target scope session

例如:

<managed-bean>
  <managed-bean-name>userBean</managed-bean-name>
  <managed-bean-class>project.UserBean</managed-bean-class>
  <managed-bean-scope>view</managed-bean-scope>
  <managed-property>
        <property-name>reset</property-name>
        <value>#{param['reset']}}</value>
  </managed-property>
</managed-bean>

有什么办法解决这个问题吗?

Any idea to solve this?

推荐答案

这是设计使然.托管属性的范围不能比托管Bean本身的范围窄.仅在bean的构建期间设置了受管属性(在您的情况下,这就是视图的开始),但是在同一视图范围内的任何后续请求中,请求参数可能不再有效,并且bean可能变成无效的状态.这种设计限制可以防止这种情况.

This is by design. The managed property cannot have a scope which is narrower than the scope of the managed bean itself. The managed property is only set during bean's construction (which is in your case thus the start of a view), but in any subsequent request within the same view scope the request parameter may not be valid anymore and the bean would possibly become in an invalid state. This design limitation prevents that.

无论如何要满足特定的功能要求,只需使用<f:viewParam>.

To achieve the particular functional requirement anyway, just use <f:viewParam> instead.

<f:metadata>
    <f:viewParam name="reset" value="#{userBean.reset}" />
</f:metadata>

另请参见:

  • ViewParam与@ManagedProperty(值=#{param.id}"")
  • See also:

    • ViewParam vs @ManagedProperty(value = "#{param.id}")
    • 这篇关于JSF属性引用范围比目标范围视图短的范围中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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