【问题标题】:Spring-JSF2 Integration: Target Unreachable, identifier 'customerBean' resolved to nullSpring-JSF2 集成:目标无法访问,标识符“customerBean”解析为 null
【发布时间】:2011-09-24 22:38:56
【问题描述】:

我正在尝试仅使用注释(不使用 faces-config.xml 定义托管 bean)对 Spring 3 和 JSF 2 进行简单集成,但我遇到了一个错误。

错误是:

javax.el.PropertyNotFoundException: /customer/add.xhtml @11,70 value="#{customerBean.firstName}": Target Unreachable, identifier 'customerBean' resolved to null

这是页面:add.xhtml

<h:body>
    <h:form>
        <label>First Name <h:inputText value="#{customerBean.firstName}" /></label><br />
        <label>Last Name <h:inputText value="#{customerBean.lastName}" /></label><br />
        <label>Email <h:inputText value="#{customerBean.email}" /></label><br />
        <h:commandButton value="Add" action="#{customerBean.add}" />
    </h:form>
</h:body>

这是 bean:CustomerBean.java

package com.devworkzph.customer.sample.bean;

@Component
@Qualifier("customerBean")
@SessionScoped
public class CustomerBean implements Serializable{
    private String firstName;
    private String lastName;
    private String email;

    public String add(){
        // code
    }
    //getters and setters
}

这是我的 applicationContext.xml 的一部分

<context:annotation-config />
<context:component-scan base-package="com.devworkzph.customer.sample" />

这是我的 web.xml 的一部分

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
    classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
  <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<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>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

有谁知道我在这里做错了什么?

谢谢!

【问题讨论】:

    标签: java spring jsf-2 annotations


    【解决方案1】:

    我刚刚将 CustomerBean.java 更改为具有以下注释:

    @Component
    @Scope("session")
    

    然后在 faces-config.xml 中添加 SpringBeanFacesELResolver。我之前把它注释掉了,不知道我需要它,即使我不会使用 faces-config 来定义 CustomerBean。

    <?xml version="1.0"?>
    <faces-config xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
       version="2.0">
    
      <application>
      <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
      </application>
    </faces-config>
    

    【讨论】:

      猜你喜欢
      • 2019-05-10
      • 2012-04-06
      • 2012-10-27
      • 2018-05-09
      • 1970-01-01
      • 2012-06-16
      • 2013-10-16
      • 2015-09-14
      • 1970-01-01
      相关资源
      最近更新 更多