Viewscoped bean 在返回同一视图时不保留其状态?
我目前正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上所有这些问题都已在此条目中得到解答..谢谢!
Basically all these questions have been answered in this entry .. Thank you !