Seam应用程序 - 目标无法访问,标识符&bean解析为null"

时间:2016-07-08 06:48:24

标签: jsf jsf-2 seam

我在我的seam应用程序上遇到目标无法访问,标识符&bean解析为null" 异常。我试图熟悉JBoss接缝,因为它仍然被我们公司使用。

Employee.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;
    }

}

EmployeeBean.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(){

    }

}

EmployeeController.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;
    }

}

Register.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:&#34; /register.xhtml   @ 17,73 value =&#34;#{employeeController.employee.username}&#34;:目标   无法访问,标识符&#39; employeeController&#39;解决为null&#34;

我正在使用JSF 2.0和Seam 2.2,请告诉我您需要解决此异常所需的配置文件。

更新

Web.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>

1 个答案:

答案 0 :(得分:0)

目标无法访问,标识符&#39; employeeController&#39;决定为null&#34;表示您的EmployeeController未被读取并放入Seam容器中。

所以你能做的就是做一些调试。当Seam容器启动时,它将显示已加载的组件(bean)的日志。尝试在日志中找到您的EmployeeController。

如果找不到,请检查根类路径中是否有seam.properties(空文件)。 seam.properties是Seam开始扫描组件的指标。