我在接缝应用程序上遇到了目标无法访问,标识符"bean 解析为空"异常。我正在尝试熟悉 JBoss 接缝,因为它仍然被我们公司使用。
员工.java
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
@Name("employee")
@Scope(ScopeType.SESSION)
public class Employee {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
员工豆.java
import javax.ejb.Remove;
import javax.ejb.Stateful;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
@Stateful
@Name("employeeBean")
@Scope(ScopeType.SESSION)
public class EmployeeBean {
public void addEmployee(Employee employee) {
System.out.println(employee.getUsername() + " is added");
}
@Remove
public void remove(){
}
}
员工控制.java
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
@Name("employeeController")
@Scope(ScopeType.SESSION)
public class EmployeeController {
@In(create = true, required = false)
private EmployeeBean employeeBean;
@In(create = true, required = false)
private Employee employee;
public void addNewEmployee() {
employeeBean.addEmployee(this.employee);
}
public EmployeeBean getEmployeeBean() {
return employeeBean;
}
public void setEmployeeBean(EmployeeBean employeeBean) {
this.employeeBean = employeeBean;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
}
注册.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:s="http://jboss.com/products/seam/taglib">
<head></head>
<body>
<f:view>
<h:form>
<h:messages />
<s:validateAll>
<h:panelGrid columns="2">
Username: <h:inputText
value="#{employeeController.employee.username}" required="true" />
Password: <h:inputSecret
value="#{employeeController.employee.password}" required="true" />
</h:panelGrid>
</s:validateAll>
<h:commandButton action="#{employeeController.addNewEmployee()}"
value="Register" />
</h:form>
</f:view>
</body>
</html>
我该如何解决这个问题?
javax.el.PropertyNotFoundException,消息:"/register.xhtml @17,73 值="#{employeeController.employee.username}":目标 无法访问,标识符"员工控制器"解析为空"
我使用的是JSF 2.0和Seam 2.2,请让我知道你需要什么配置文件来解决这个异常。
更新:
网络.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>seam</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>*.seam</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.jboss.jbossfaces.JSF_CONFIG_NAME</param-name>
<param-value>Mojarra-1.2</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
</web-app>
目标不可达,标识符'employeeController'解析为空"表示你的EmployeeController没有被读取并放入Seam容器中。
所以你可以做的是做一些调试。当Seam容器启动时,它将显示加载的组件(bean)的日志。尝试在日志中找到您的员工控制器。
如果找不到,请检查根类路径中是否有seam.properties(空文件)。seam.properties是Seam将开始扫描组件的指标。