Viewscoped bean 在返回同一视图时不保留其状态?

发布于 2024-10-27 04:09:45 字数 949 浏览 1 评论 0原文

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

我注意到了这种行为。

当有这个按钮时:

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

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

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

<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 都会 始终保留其状态 返回到相同的视图。

请分享您的意见!

谢谢 .....

Im currently testing on JSF Bean that make use of ViewScope

I notice this behaviour.

When having this button :

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

I can see the postconstruct happens only once, and the submission triggered by this button doest trigger postconstruct, which is correct, since it's returning to the same view.

But when i add modify my button into this :

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

I can see that the postconstruct method gets called for every submission, which means the bean doesnt retain it's state, although it's actualy returning to the same view. I thought this is because of the redirectin, so i omitted it, and the button becomes something like this :

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

But still, the postconstruct method gets called for every submission, which is not desireable.

Is it possible to have this idealism :

No matter whether it's explicitly or
implicily defined (via attribute or
via return "myview.xhtml" in action
method) , whether it's using redirect
or not, the viewscoped bean will
always retain it's state when
returning to the same view.

Please share your opinions !

Thank you .....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤浅笑 2024-11-03 04:09:45

基本上所有这些问题都已在此条目中得到解答..谢谢!

Basically all these questions have been answered in this entry .. Thank you !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文