将托管bean注入另一个时获取ManagedBeanCreationException

时间:2013-05-18 04:34:43

标签: jsf-2

在我的JSF2-Primefaces3 web应用程序中,我从bean“CityBean”引用名为“HomeBean”的bean我正在使用ManagedBean注释,并且根本没有faces-config.xml。请找到如下代码:

HomeBean

@ManagedBean(name="HmBen")
@SessionScoped
public class HomeBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(HomeBean.class);

    private List<Offer> offersList;

    public HomeBean() {       
    }    
}

CityBean

@ManagedBean(name="CtyBen")
@SessionScoped
public class CityBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @ManagedProperty(value="#{HmBen}")
    private HomeBean homeBean;         

    public CityBean() {       
    }

    /**
     * Following setters are required as per the documentation for Dependancy
     * Injection of beans to work
     */
    public void setHomeBean(HomeBean homeBean) {
            this.homeBean = homeBean;
    }    
}

注意:由于Stackoverflow强加的字符限制,这只是代码的一部分。

我遇到以下异常:

Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Unable to set property homeBean for managed bean CtyBen
    at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:615)
    at com.sun.faces.mgbean.ManagedBeanBuilder.buildBean(ManagedBeanBuilder.java:133)
    ... 20 more
Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2377)

有没有人对此有任何线索?

1 个答案:

答案 0 :(得分:0)

已经提交的回复让我解释一下这是什么意思。页面呈现它从上到下呈现。服务器以字节为单位给出响在渲染一些字节后,服务器获得通知(如果在页面上有条件),那么现在你必须渲染字节,服务器不能占用当时已发送给用户的字节服务器抛出IllegalState异常。提供.xhtml页面。请检查一年前我发布的以下问题。 Jsf2.0 forwarding page error without parameter