1
votes

I have one managed bean in viewscope i want to reset form which is using this scope. According to Baluc from this post Reset JSF Backing Bean(View or Session Scope)
I did the same in my code :

    public String reset(){
         FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("myBean");
        return "SamePage?faces-redirect=true"; 

    }

But it is not working. Can some tell any solution .

2
Please describe the error. "Not working" is not specific enough.Matt Handy

2 Answers

4
votes

try this

public void reset(){

     FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("myBean");

}

or this

public String reset(){

     return "SamePage"; 

}
0
votes

The idea is that, by returning something non-null and non-void, you don't need that call to FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("myBean"). The following should work (eventually):

public String reset() {
    return "";
}

I say "eventually" because I don't remember if the view-scoped beans are destroyed before or after the render response phase. I suspect that's why BalusC suggested adding ?faces-redirect=true to the return value.