I have seen Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
I have followed the steps mentioned there for the use case:
- @Named annotation, using Java EE 6
and everything that is specified there is as it is in my project.
xhtml file; please note I have checked the syntax value="#{course.credits}"
<html xmlns="http://www.w3.org/1999/xhtml" mlns:f="http://java.sun.com/jsf/core" 
 xmlns:h="http://java.sun.com/jsf/html"> 
<head><title>Add Course</title></head> 
 <body> 
  <h2>Course Details</h2>      
  <h:form> 
    <table> 
      <tr> 
        <td>Name:</td> 
        <td><h:inputText id="course_name" value="#{course.name}"/></td> 
      </tr> 
      <tr> 
        <td>Credits:</td> 
        <td> 
          <h:inputText id="course_credits" 
           value="#{course.credits}"/> 
        </td> 
      </tr> 
      <tr> 
        <td colspan="2"><h:commandButton value="Submit" action="#{course.addCourse}"/></td> 
      </tr> 
    </table> 
  </h:form> 
</body> 
The @Named("course") bean; please note I have checked the imports:
package packt.jee.eclipse.jms.jsf_bean;    
import java.io.Serializable;    
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;    
import packt.jee.eclipse.jms.dto.CourseDTO;
@Named("course")
@RequestScoped
public class CourseJSFBean implements Serializable {
    public static final long serialVersionUID = 2L;         
    private CourseDTO courseDTO = new CourseDTO();
    @Inject
    private CourseManagedMsgSenderBean courseMessageSender;
    public String getName() {
        return this.courseDTO.getName();
    }
    public void setName(String name) {
        this.courseDTO.setName(name);
    }
    public int getCredits() {
        return this.courseDTO.getCredits();
    }
    public void setCredits(int credits) {
        this.courseDTO.setCredits(credits);
    }
    public void addCourse() throws Exception {
        courseMessageSender.addCourse(courseDTO);
    }
}
The beans.xml in META-INF/beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
I have restarted Eclipse, cleaned the project, restarted the server, but I am still getting this error. Just for the avoidance of doubt the error message is
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'course' resolved to null
Clearly I am making a mistake but I can't see what.
I am using Glassfish 5 with eclipse 4.8 and jdk 8.
Only other thing I can think of is that there is no war file - stuff I've read about solving this error has mentioned stuff like "make sure your war file is in xxx directory" but I have no war file. I'm just adding to the server and right-clicking on the xhtml file and selecting run on server.
Any assistance is appreciated.
EDIT: My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
  <display-name>CourseManagementJMSWeb</display-name>
  <welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>  
    <servlet>
        <servlet-name>JSFServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>JSFServlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>    
</web-app>
I have no faces-config.xml.
There are class files in the project directory in glassfish:
I have tried changing the annotation @RequestScoped to @ViewScoped but it did not make any difference.
EDIT 2: My book states that beans.xml goes in WebContent/META-INF:
In any case I already looked to this as a possible cause so I put an identical beans.xml in both META-INF and WEB-INF, but it made no difference:
There is nothing in my book that says anything about deploying any jar, war, or ear file. I have mentioned this already in my question. I am entirely new to this so I do not know whether this is odd or not.
EDIT 3: I have created a small basic test class and xhtml file in the same project and I am getting the same error:
test.TestJSFBean.java:
package test;    
import java.io.Serializable;    
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;    
@Named
@RequestScoped
public class TestJSFBean implements Serializable {
    private String name;
    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name=name;
    }
    public void add() throws Exception {
        System.out.println("TestJSFBean.add");
    }
}
test.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> 
<head> 
  <title>TEST</title> 
</head> 
 <body> 
  <h2>TEST</h2>  
  <h:form> 
    <table> 
      <tr> 
        <td>Name:</td><td><h:inputText id="name" value="#{TestJSFBean.name}"/></td> 
      </tr> 
      <tr> 
        <td colspan="2"><h:commandButton value="Submit" action="#{TestJSFBean.add}"/></td> 
      </tr> 
    </table> 
  </h:form>  
</body> 
</html>
Error:
  /test.xhtml @16,65 value="#{TestJSFBean.name}": Target Unreachable, identifier 'TestJSFBean' resolved to null
javax.el.PropertyNotFoundException: /test.xhtml @16,65 value="#{TestJSFBean.name}": Target Unreachable, identifier 'TestJSFBean' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:106)
Edit 4: I have tried
<td>Name:</td><td><h:inputText id="name" value="#{testJSFBean.name}"/></td> 
(i.e. rather than "#{TestJSFBean.name}") and that didn't work either:
javax.servlet.ServletException: /test.xhtml @10,79 value="#{testJSFBean.name}": Target Unreachable, identifier 'testJSFBean' resolved to null



