0

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:

.class files 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:

beans.xml location

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:

beans.xml locations

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
JL_SO
  • 1,321
  • 16
  • 25
  • Thanks, I just tried that, but it didn't work. BTW I used javax.faces.view.ViewScoped; as the alternative was marked as deprecated. Edit - the comment I'm replying to has disappeared. It suggested changing @ RequestScoped to @ ViewScoped – JL_SO Aug 22 '18 at 11:49
  • The duplicate you found tells to put beans.xml in WEB-INF. Why exactly is yours in META-INF? Based on the Windows explorer screenshot you don't seem to be developing a web module JAR file at all. – BalusC Aug 22 '18 at 16:56
  • @BalusC My book states that beans.xml needs to go in WebContent/META-INF. In any case I have looked into this already so I have an identical beans.xml in META-INF and WEB-INF. I have updated my question. – JL_SO Aug 23 '18 at 01:18
  • @BalusC yes there is no jar. There is nothing mentioned regarding this particular project in my book about jars, wars, or ears. I did mention above that I thought this might be odd but I only started learning Java EE four days ago so I don't have the knowledge to know if this is an issue or not. There are however classes in the project directory as indicated by my screenshot. Thanks anyway. – JL_SO Aug 23 '18 at 01:31
  • Updated original question with simple test class and xhtml; it doesn't work. – JL_SO Aug 23 '18 at 02:06
  • Glassfish 5 and javaee 6? Sure? can you resolve the bean in EL in a jsp? – Kukeltje Aug 23 '18 at 07:00
  • The duplicate you found tells that the default name of a `@Named` bean is **not** the class name. So `#{TestJSFBean}` is in first place already wrong. – BalusC Aug 23 '18 at 08:58
  • @BalusC "The duplicate you found" Sorry what duplicate that I found? I don't understand your comment. Oh you mean the stackoverlflow post? Well I tried it at first with @Named("test") but that didn't work so I removed the alias. I don't understand the rest of your comment so I will look at that post now. Edit I see now, I need to lowercase the first character; I will try that and come back and post the results. – JL_SO Aug 23 '18 at 15:21
  • @BalusC It didn't work: javax.servlet.ServletException: /test.xhtml @ 10,79 value="#{testJSFBean.name}": Target Unreachable, identifier 'testJSFBean' resolved to null – JL_SO Aug 23 '18 at 17:56
  • 1
    Can you post the full stack trace from your console? I suspect the reason that the bean was never put into service comes a lot earlier than you'd expect. Also, `` is a no-no in JSF; use `` otherwise a bunch of necessary JSF javascript won't get injected into your page. – kolossus Aug 28 '18 at 02:10
  • Use `h:head` and `h:body` with xhtml. – Xtreme Biker Sep 06 '18 at 06:43

0 Answers0