Spring-JSF2 集成:目标无法访问,标识符“customerBean”解析为 null
我正在尝试仅使用注释(不使用 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>
有谁知道我在这里做错了什么?
谢谢!
I'm trying a simple integration of Spring 3 and JSF 2 using annotations only (not using faces-config.xml to define managed beans) and I'm stuck with an error.
The error is:
javax.el.PropertyNotFoundException: /customer/add.xhtml @11,70 value="#{customerBean.firstName}": Target Unreachable, identifier 'customerBean' resolved to null
This is the page: 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>
This is the 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
}
This is a part of my applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="com.devworkzph.customer.sample" />
This is a part of my 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>
Does anyone know what I'm doing wrong here?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚将 CustomerBean.java 更改为具有以下注释:
然后在 faces-config.xml 中添加 SpringBeanFacesELResolver。我之前已将其注释掉,但不知道即使我不会使用 faces-config 来定义 CustomerBean,我也需要它。
I just changed CustomerBean.java to have the following annotations:
Then added SpringBeanFacesELResolver in faces-config.xml. I had it commented out before, not knowing that I needed it even if I won't use faces-config to define CustomerBean.