JSF Property references object in a scope with shorter lifetime than the target scope view

前端 未结 1 383
星月不相逢
星月不相逢 2021-01-23 04:13

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:

<         


        
相关标签:
1条回答
  • 2021-01-23 05: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:

    • ViewParam vs @ManagedProperty(value = "#{param.id}")
    0 讨论(0)
提交回复
热议问题