JSF Property references object in a scope with sho

2019-02-25 23:50发布

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:

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

For example:

<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?

标签: jsf scope
1条回答
Fickle 薄情
2楼-- · 2019-02-26 00:02

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.

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

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

See also:

查看更多
登录 后发表回答