Reputation: 111
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 .
Upvotes: 1
Views: 4986
Reputation: 41
try this
public void reset(){
FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("myBean");
}
or this
public String reset(){
return "SamePage";
}
Upvotes: 4
Reputation: 477
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.
Upvotes: 0