JSF2 无法从 ViewScoped 作为 ManagedProperty 访问 SessionScoped bean
我有一个奇怪的问题。 Afaik 我可以将 SessionScoped bean 注入到 viewscoped 中,因为它比另一个更广泛。这是我的代码:
@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 时它失败:
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
为什么? :)
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;
}
The 2 managed bean:
@ManagedBean
@SessionScoped
public class ProjectCurrentBean implements Serializable {
and
@ManagedBean
@SessionScoped
public class UserCredentialsBean implements Serializable {
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
why? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未使用
javax.faces.bean
包,而是来自javax.enterprise.context
包。这不能与javax.faces.bean
包中的@ManagedBean
结合使用。然后,该 bean 将默认为请求范围,其行为类似于 <代码>@RequestScoped。修复您的进口。
You've not declared the bean using
@SessionScoped
fromjavax.faces.bean
package, but instead fromjavax.enterprise.context
package. This don't work in combination with@ManagedBean
fromjavax.faces.bean
package. The bean will then default to the request scope and behave like@RequestScoped
.Fix your imports.