[英]JSF SessionScoped managedBean in conjunction with ViewScoped managedBean
I have the following problem in my project: 我的项目中存在以下问题:
We have 2 managed beans with the following configuration: 我们有2个具有以下配置的托管bean:
@ManagedBean
@SessionScoped
public class SessionBean {
private PersonnelFile personnelFile; // + getters/setters
}
@ManagedBean
@ViewScoped
public class ViewBean {
@ManagedProperty("#{sessionBean}")
private SessionBean sessionBean;
public void selectPersonnel() {
sessionBean.getPersonnelFile().setPerson(new Person());
}
}
This is not all of the code, but it gives you a general idea of the sitatution: 这不是全部代码,但是它为您提供了大致的概念:
The problem now is: 现在的问题是:
null
, meaning he 'lost' the session information about that object 但是,我之前在SessionScoped bean中设置的对象已变为null
,这意味着他“丢失”了有关该对象的会话信息。 If you want more explanation or if you want me to phrase this question better, let me know or use the edit button! 如果您需要更多说明,或者希望我更好地表达这个问题,请告诉我或使用“编辑”按钮!
@BalusC I think we may have found the problem. @BalusC我想我们可能已经找到了问题。 In our web.xml, we were using the following setting: 在我们的web.xml中,我们使用以下设置:
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
Now, if I understand it correctly, we can't edit the state of a session-scoped bean through a view-scoped bean with this setting... The only way we have been able to change the state of the session-scoped bean, is in the constructor or PostConstruct method of the bean itself. 现在,如果我正确理解它,我们将无法通过具有此设置的视图范围的Bean编辑会话范围的Bean的状态...我们唯一能够更改会话范围的Bean的状态的方法,位于bean本身的构造函数或PostConstruct方法中。 Changes made to the session-scoped bean from inside the view-scoped bean were not persisted on the server. 从视图范围的Bean内部对会话范围的Bean所做的更改未持久保存在服务器上。
If we set this variable to 'server', the state is indeed persisted on the server and not transmitted to the client every time. 如果我们将此变量设置为“ server”,则状态确实会保留在服务器上,并且不会每次都传输给客户端。 I understand this puts more load on the server in terms of memory, but I would like to know how we could solve our problem by using the client
approach. 我知道这会给服务器增加内存方面的负担,但是我想知道如何使用client
方法解决问题。
So, my problem is fixed, but I'm not sure if the solution is ideal... 因此,我的问题已解决,但是我不确定该解决方案是否理想...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.