Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf Viewscoped bean在返回到同一视图时不保留其状态?_Jsf_Jsf 2 - Fatal编程技术网

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

Jsf Viewscoped bean在返回到同一视图时不保留其状态?,jsf,jsf-2,Jsf,Jsf 2,Im目前正在测试使用ViewScope的JSFbean 我注意到这种行为 使用此按钮时: <p:commandButton value="Submit Data to Server" ajax="false" update="debugPanel" /> 我可以看到postconstruct只发生一次,这个按钮触发的提交不会触发postconstruct,这是正确的,因为它返回到相同的视图 但当我将“修改我的按钮”添加到此中时: <p:commandButton v

Im目前正在测试使用ViewScope的JSFbean

我注意到这种行为

使用此按钮时:

<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方法,这是不可取的

有没有可能有这样的理想主义:

不管它是明确的还是明确的 通过属性或属性隐式定义 通过运行中的return myview.xhtml 方法,无论是否使用重定向 或者不,viewscoped bean将 当需要时,始终保持其状态 返回到相同的视图

请分享你的意见


谢谢你……

基本上所有这些问题都在这篇文章中得到了回答。。谢谢大家!

你实施了吗?这可能是原因。@BalusC:不,我在这个案子里没有。由于没有明确说明目标视图,它仍然可以正常工作,这是原始文章中的第一种情况。