Reset JSF Backing Bean(View or Session Scope)

前端 未结 5 1177
南方客
南方客 2020-12-14 04:36

I want to reset by JSF backing bean when some method is invoked. Assume that there is a command button, someone press it and after succesfull transaction, my View or Session

5条回答
  •  悲哀的现实
    2020-12-14 05:07

    A view scoped bean will be recreated when you return non-null or non-void from the action method, even if it would go back to the same view. So, just return a String from the action method, even if it's just an empty string:

    public String submit() {
        // ...
    
        return "";
    }
    

    To make it complete, you could consider sending a redirect by appending the ?faces-redirect=true query string to the returned outcome.

    public String submit() {
        // ...
    
        return "viewId?faces-redirect=true";
    }
    

    A session scoped bean is in first place the wrong scope for whatever you're currently trying to achieve. The bean in question should have been be a view scoped one. Ignoring that, you could just recreate the model in the action method, or very maybe invalidate the session altogether (which would only also destroy all other view and session scoped beans, not sure if that is what you're after though).

提交回复
热议问题