【问题标题】:Reset JSF Backing Bean of Viewscope重置 Viewscope 的 JSF Backing Bean
【发布时间】:2012-06-05 10:34:32
【问题描述】:

我在 viewscope 中有一个托管 bean,我想重置使用此范围的表单。根据这篇文章中的 Baluc Reset JSF Backing Bean(View or Session Scope)
我在我的代码中做了同样的事情:

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

    }

但它不起作用。 有人可以告诉任何解决方案。

【问题讨论】:

  • 请描述错误。 “不工作”不够具体。

标签: jsf-2


【解决方案1】:

试试这个

public void reset(){

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

}

或者这个

public String reset(){

     return "SamePage"; 

}

【讨论】:

  • 好!第一个选项帮助了我! +1
【解决方案2】:

这个想法是,通过返回非 null 和非 void 的内容,您不需要调用 FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("myBean")。以下应该工作(最终):

public String reset() {
    return "";
}

我说“最终”是因为我不记得视图范围的 bean 是在渲染响应阶段之前还是之后销毁的。我怀疑这就是为什么 BalusC 建议在返回值中添加 ?faces-redirect=true

【讨论】:

    猜你喜欢
    • 2012-10-10
    • 2014-08-11
    • 2013-03-24
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 2014-03-09
    • 2012-02-10
    • 1970-01-01
    相关资源
    最近更新 更多