Problem similar to:
Target Unreachable, identifier resolved to null JSF 2.2
How to reference JSF managed beans which are provided in a JAR file?
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
Java EE 6: Target Unreachable, identifier 'helloBean' resolved to null
But none of resolutions helped me. When I click command button (on page, please see xhtml file) I got:
An Error Occurred:
javax.el.PropertyNotFoundException: /navigate.xhtml @15,90 action="#{navigator.choosePage}": Target Unreachable, identifier 'navigator' resolved to null
I can get why. Why this bean is not visible in jsf?
Using java8, j2ee 7, tomcat 6.0.44
My pom.xml:
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>jsfTut</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JSF deps -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.12</version>
</dependency>
<!-- others -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.3</version>
</dependency>
</dependencies>
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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-app_3_1.xsd"
version="3.1">
<display-name>JSF</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>JSF</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSF</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSF</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" 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_2.xsd">
</faces-config>
Simple class:
package pl.sarseth.jsf;
import javax.faces.bean.ManagedBean;
@ManagedBean(name = "navigator")
public class Navigator {
public String choosePage(){
if(Math.random() > 0.5){
return "result-page-1";
} else {
return "result-page-2";
}
}
}
And xhtml file:
<?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://xmlns.jcp.org/jsf/html">
<h:head>
<title>My JSF page</title>
</h:head>
<h:body>
<h1>Navigate via Java</h1>
<fieldset>
<legend>Use Java to Navigate to Results Page</legend>
<h:form>
Press button to get one of two possible results pages.<br/>
<h:commandButton value="Go to Random Page" action="#{navigator.choosePage}"/>
</h:form>
</fieldset>
</h:body>
</html>
Project structure is this:
project
---src
---main
---java
---pl.sarseth.jsf
---Navigator.java
---webapp
---WEB-INF
---faces-config.xml
---web.xml
---index.xhtml
---navigate.xhtml
---pom.xml