JSF2无法从ViewScoped作为ManagedProperty到达SessionScoped bean [英] JSF2 Can't reach SessionScoped bean from ViewScoped as ManagedProperty
问题描述
我有一个奇怪的问题. Afaik我可以将一个SessionScoped bean注入到一个视域中,因为它比其他的更为广泛.这是我的代码:
I have a strange problem. Afaik I can inject a SessionScoped bean into a viewscoped, because its broader, than the other. Here is my code:
@ManagedBean
@ViewScoped
public class ProjectBean implements Serializable {
@ManagedProperty(value="#{projectCurrentBean}")
private ProjectCurrentBean currentBean;
public void setCurrentBean(ProjectCurrentBean currentBean) {
this.currentBean = currentBean;
}
@ManagedProperty(value="#{userCredentialsBean}")
private UserCredentialsBean activeUser;
public void setActiveUser(UserCredentialsBean activeUser) {
this.activeUser = activeUser;
}
2个托管bean:
@ManagedBean
@SessionScoped
public class ProjectCurrentBean implements Serializable {
和
@ManagedBean
@SessionScoped
public class UserCredentialsBean implements Serializable {
它与UserCredentialsBean可以正常工作,但是当我放入ProjectCurrentBean时,它会失败:
It works fine with the UserCredentialsBean, but when I put the ProjectCurrentBean it fails:
Unable to create managed bean projectBean. The following problems were found: - The scope of the object referenced by expression #{projectCurrentBean}, request, is shorter than the referring managed beans (projectBean) scope of view
为什么? :)
推荐答案
您尚未使用 javax.enterprise.context
包.这不能与javax.faces.bean
包中的@ManagedBean
结合使用.然后,该Bean将默认为请求范围,其行为类似于 @RequestScoped
.
You've not declared the bean using @SessionScoped
from javax.faces.bean
package, but instead from javax.enterprise.context
package. This don't work in combination with @ManagedBean
from javax.faces.bean
package. The bean will then default to the request scope and behave like @RequestScoped
.
修复您的进口商品.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class ProjectCurrentBean implements Serializable {
这篇关于JSF2无法从ViewScoped作为ManagedProperty到达SessionScoped bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!