【问题标题】:JSF Property references object in a scope with shorter lifetime than the target scope viewJSF 属性引用范围内的对象,其生命周期比目标范围视图短
【发布时间】:2012-08-01 08:45:34
【问题描述】:

我有一个视图范围的托管 bean,其托管属性绑定到查询字符串参数。 JSF 给了我熟悉的例外:

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>

有办法解决这个问题吗?

【问题讨论】:

    标签: jsf scope


    【解决方案1】:

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

    无论如何,要实现特定的功能要求,只需使用&lt;f:viewParam&gt;

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

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多