# Beispiel wirft Fehler. JSF 2.0 / Tomcat / Eclipse



## akchill (14. Sep 2010)

Hallo zusammen,

ich habe mir das Buch JAVAServer Faces 2.0 gekauft. Dort wurde eine Seite erwähnt wo ich die Beispiele mir anschauen kann, dies habe ich getan. Jetzt wenn ich das erste Beispiel laufen lassen will, zeigt er mir folgenden Fehler an.


```
14.09.2010 08:19:39 com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNUNG: /editCustomer.xhtml @16,72 value="#{customer.firstName}": Target Unreachable, identifier 'customer' resolved to null
javax.el.PropertyNotFoundException: /editCustomer.xhtml @16,72 value="#{customer.firstName}": Target Unreachable, identifier 'customer' resolved to null
	at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:93)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
	at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1008)
	at javax.faces.component.UIInput.validate(UIInput.java:934)
	at javax.faces.component.UIInput.executeValidate(UIInput.java:1189)
	at javax.faces.component.UIInput.processValidators(UIInput.java:691)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
	at javax.faces.component.UIForm.processValidators(UIForm.java:243)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
	at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1180)
	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)
14.09.2010 08:19:39 org.apache.catalina.core.StandardWrapperValve invoke
SCHWERWIEGEND: Servlet.service() for servlet Faces Servlet threw exception
javax.el.PropertyNotFoundException: /editCustomer.xhtml @16,72 value="#{customer.firstName}": Target Unreachable, identifier 'customer' resolved to null
	at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:93)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
	at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1008)
	at javax.faces.component.UIInput.validate(UIInput.java:934)
	at javax.faces.component.UIInput.executeValidate(UIInput.java:1189)
	at javax.faces.component.UIInput.processValidators(UIInput.java:691)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
	at javax.faces.component.UIForm.processValidators(UIForm.java:243)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
	at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1180)
	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)
```


Nach langem suchen finde ich den Fehler einfach nicht.

Der Fehler kann eig. nicht ein größerer sein, da dass beispiel ein kleines ist. 


Fehler bei dem Klick ausgelöst wird:

```
<?xml version="1.0" encoding="UTF-8"?>
<!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">
<head>
	<title>MyGourmet - Edit Customer</title>
</head>
<body>
    <h1><h:outputText value="MyGourmet"/></h1>
    <h2><h:outputText value="Edit Customer"/></h2>
    <h:form id="form">
        <h:panelGrid id="grid" columns="2">
            <h:outputLabel value="First Name:" for="firstName"/>
            <h:inputText id="firstName" value="#{customer.firstName}"/>
            <h:outputLabel value="Last Name:" for="lastName"/>
            <h:inputText id="lastName" value="#{customer.lastName}"/>
            <h:commandButton id="save" action="#{customer.save}" value="Save"/>
        </h:panelGrid>
    </h:form>
</body>
</html>
```

Bean Klasse:

```
package webtest.WebContent.java.

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/*
 * customer profile
 */
@ManagedBean
@SessionScoped
public class customer {
	private String firstName;
	private String lastName;

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String save() {
		return "/showCustomer.xhtml";
	}

}
```

web.xml

```
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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/web-app_2_5.xsd"
		version="2.5">

	<description>JavaServer Faces 2.0 - MyGourmet 1</description>

	<!-- Faces Servlet -->
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Faces Servlet Mapping -->
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.jsf</url-pattern>
	</servlet-mapping>

	<!-- Welcome files -->
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>

</web-app>
```

Java-Config.xml

```
<?xml version="1.0"?>
<faces-config 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/web-facesconfig_2_0.xsd"
		version="2.0">

    <!-- No special configuration needed for MyGourmet 1 -->

</faces-config>
```

Eventuell liegt es am Package wo die Customer.java datei ist?









Danke mit freundlichen Grüßen

AKCHILL!


----------



## akchill (14. Sep 2010)

gelöst!


----------



## JohannisderKaeufer (14. Sep 2010)

Und wie?

Die Klasse customer.java

1. schreibt man aus konvention Groß also Customer.java und public class Customer.
2. gehört diese Klasse nicht in Webcontent - JS (JavaScript) sondern unter Java Resources:src

Ausserdem gehören auch die log4j.properties in den Ordner Java Resources : src


----------

