3

After digging through links such as the following, I'm unable to solve the problem: Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable

I am getting the following error: javax.servlet.ServletException: /Project9.xhtml @13,55 value="#{ProjectBean.income}": Target Unreachable, identifier [ProjectBean] resolved to null

My form:

<!DOCTYPE html>
 <html xmlns="http://wwww3.org/1999/xhtml"
  xmlns:a="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  >
<h:head>
<title>Project9</title>
</h:head>

<h:body>
<h:form>
    Income: <h:inputText value="#{ProjectBean.income}"/>
    Number of people: <h:inputText value="#{ProjectBean.numPeople}"/>
        <h:commandButton value= "Submit" action= "Project9response"/>
</h:form>

</h:body>
</html>

I am not sure whether the right convention is wwww3.org or www.3.org but I have tried them both.

My Response page:

<!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:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  >
<h:head>
<title><ui:insert name="title">Project 9 response</ui:insert></title>
</h:head>


<h:body>
Am I above the poverty level: #{ProjectBean.abovePovertyLevel()}

</h:body>

</html>

My Bean:

@ManagedBean
@SessionScoped
public class ProjectBean implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private double income;
private double numPeople;

//constructor is no arg
public ProjectBean() {

}

public double getIncome() {
    return income;
}
public void setIncome(double income) {
    this.income = income;
}
public double getNumPeople() {
    return numPeople;
}
public void setNumPeople(double numPeople) {
    this.numPeople = numPeople;
}

public boolean abovePovertyLevel() {
    if ( income < (16460.00 + 4320.00) * (numPeople - 2)){
        return false;
    }
    else {
    return true;
}
}

}

My faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">

</faces-config>

I have my faces-config.xml and my javax-faces.2.2.8.jar file in the lib folder of WEB-INF I have my bean in the src folder of Java Resources

I have another project called helloworld with several little JSF projects that all work, and I have tried copying project9 into helloworld and running it, but I get the same error only on that project

I have tried cleaning my project as people have suggested

This is a student project and my first introduction to JSF and Tomcat. I'm using a Mac and Eclipse photon.

As I stated in a comment in my code, if I try to bypass the response xhtml file and go straight to the javabean method in my html form, I get an underline under ProjectBean.abovePovertyLevel() and the error "the action value does not match a navigation case outcome"

I'm not sure of some of the answers in the link above regarding CDI, etc, that all is above my head at this point.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Julie Pixie
  • 461
  • 2
  • 9
  • 27

2 Answers2

3

Replace all the #{ProjectBean. by #{projectBean. (make the first character lowercase).

This is because you need to refer to the managed bean by name, not by the classname. By default, jsf will generate this name for you, as per the docs at https://docs.oracle.com/javaee/6/api/javax/faces/bean/ManagedBean.html :

If the value of the name attribute is unspecified or is the empty String, the managed-bean-name is derived from taking the unqualified class name portion of the fully qualified class name and converting the first character to lower case. For example, if the ManagedBean annotation is on a class with the fully qualified class name com.example.Bean, and there is no name attribute on the annotation, the managed-bean-name is taken to be bean.

racraman
  • 4,410
  • 1
  • 12
  • 15
2

Nevermind, I JUST solved this Added a name to my annotation as such: @ManagedBean(name="ProjectBean")

Also I realized that my method was wrong if I didn't declare poverty level first

int povertyLevel = (16460 + 4230 * (numPeople-2));
    if(income > povertyLevel)
        return true;
    else{
    return false;
    }

This seemed to work

Julie Pixie
  • 461
  • 2
  • 9
  • 27