JSF2无法从ViewScoped作为ManagedProperty到达SessionScoped bean [英] JSF2 Can't reach SessionScoped bean from ViewScoped as ManagedProperty

查看:111
本文介绍了JSF2无法从ViewScoped作为ManagedProperty到达SessionScoped bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题. 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

为什么? :)

推荐答案

您尚未使用 @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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆