0

I encountered a Target Unreachable, identifier 'bean resolved to null" exception on my seam application. I'm trying to familiarize JBoss seam since it is still used by our company.

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>

How do I fix this?

javax.el.PropertyNotFoundException with message: "/register.xhtml @17,73 value="#{employeeController.employee.username}": Target Unreachable, identifier 'employeeController' resolved to null"

I'm using JSF 2.0 and Seam 2.2, please let me know what configuration files you need for this exception to be solved.

UPDATE:

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>
zbryan
  • 805
  • 2
  • 12
  • 24
  • Could you post your web.xml file? Try to see [here](http://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable) for common causes, it's not seam specific but it can help you. – SiMag Jul 08 '16 at 08:55
  • I already looked on that post by BalusC but I can't seem to make it work. Please see my update, regarding the web.xml – zbryan Jul 08 '16 at 09:11

1 Answers1

0

Target Unreachable, identifier 'employeeController' resolved to null" mean your EmployeeController is not read and put into Seam container.

So what you can do is do some debug. When Seam container start it will show the log on the the components ( beans ) those are loaded. Try to find your EmployeeController in the log.

If you can not find it, check if you have seam.properties ( an empty file ) in your root classpath. seam.properties is the indicator that where Seam will start to scan for components.

Lê Thọ
  • 334
  • 1
  • 9