【问题标题】:Viewscoped bean doesnt retain it's state when returning to the same view? [duplicate]Viewscoped bean 在返回到同一个视图时不保留它的状态? [复制]
【发布时间】:2011-03-25 08:37:42
【问题描述】:

我目前正在测试使用 ViewScope 的 JSF Bean

我注意到了这种行为。

当有这个按钮时:

<p:commandButton value="Submit Data to Server" 
    ajax="false" update="debugPanel" />

我可以看到 postconstruct 只发生一次,并且此按钮触发的提交不会触发 postconstruct,这是正确的,因为它返回到相同的视图。

但是当我添加修改我的按钮时:

<p:commandButton value="Submit Data to Server" 
    ajax="false" update="debugPanel" 
    action="viewScope2.xhtml?faces-redirect=false"/>

我可以看到每次提交都会调用 postconstruct 方法,这意味着 bean 不会保留它的状态,尽管它实际上是返回到相同的视图。我认为这是因为重定向,所以我省略了它,按钮变成了这样:

<p:commandButton value="Submit Data to Server" 
    ajax="false" update="debugPanel" 
    action="viewScope2.xhtml"/>

但是,每次提交都会调用 postconstruct 方法,这是不可取的。

有没有可能有这种理想主义:

无论是明确的还是 隐含定义(通过属性或 通过在操作中返回“myview.xhtml” method) ,是否使用重定向 与否,viewscoped bean 将 总是保持它的状态 返回相同的视图。

请分享您的意见!

谢谢你.....

【问题讨论】:

标签: jsf jsf-2


【解决方案1】:

基本上所有这些问题都在这个entry 中得到了解答。谢谢!

【讨论】:

    猜你喜欢
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    相关资源
    最近更新 更多