JSF将多个bean注入后备bean

时间:2014-08-11 19:53:06

标签: spring jsf primefaces managed-bean

我正在使用ManagedProperty在我的支持bean中注入两个bean。支持bean是视图范围,模型bean是请求范围,如下所示:

@ManagedBean(name = "categoryBB")
@ViewScoped
public class CategoryBackingBean implements Serializable {

private static final long serialVersionUID = -880184144170934066L;
private static final Logger LOG = Logger
        .getLogger(CategoryBackingBean.class);

@ManagedProperty("#{categoryService}")
CategoryService categoryService;

@ManagedProperty("#{categoryBean}")
CategoryBean categoryBean;

//Getters/Setters...
}

但是我收到以下错误:

javax.servlet.ServletException: Unable to create managed bean categoryBB

发现了以下问题:

The scope of the object referenced by expression #{categoryBean}, request, is shorter than the referring managed beans (categoryBB) scope of view
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)

我的web.xml

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-security.xml
        /WEB-INF/applicationContext.xml
     </param-value>
</context-param>
<!-- Enable Spring-Security TagLib in JSF -->
<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

有什么建议吗?

0 个答案:

没有答案