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?
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:
- ViewParam vs @ManagedProperty(value = "#{param.id}")