I am just testing out this JSF page, so I don't set the action
attribute in the <h:commandButton/>
. This is a very simple form with 3 input boxes for First Name, Last Name, and Email, and one button called Save. Every time I click that button, I receive this error
javax.el.PropertyNotFoundException: /index.xhtml @19,106 value="#{person.firstName}": Target Unreachable, identifier 'person' resolved to null
but if I annotate my JavaBean @ManagedBean
, then the form go through just fine, but every time I switch back to using @Named
Bean, I receive that error again. I have tried some of the suggestions I found on this site such as restarting the server, checking the presence of the getters, but those did not help.
<?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"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta charset="UTF-8" />
<title>Simple Form Created Using Facelets</title>
</h:head>
<h:body>
<h:messages/>
<h:form>
<h:panelGrid columns="2" columnClasses="rightColumn, leftColumn">
<h:outputLabel for="firstName" value="First Name:" />
<h:inputText id="firstName" value="#{person.firstName}"
label="First Name"/>
<h:outputLabel for="lastName" value="Last Name:" />
<h:inputText id="lastName" value="#{person.lastName}" label="Last Name"/>
<h:outputLabel for="email" value="Email:"/>
<h:inputText id="email" value="#{person.email}" label="Email" />
<h:panelGroup />
<h:commandButton value="Submit"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
This is my JavaBean class
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
public class Person {
private String firstName = "empty";
private String lastName = "empty";
private String email = "empty";
public void Person() {}
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 getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
This is the web.xml
file.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
/WEB-INF/beans.xml
? – CopalmRequestScoped
should bejavax.enterprise.context.RequestScoped
forCDI
. Do not mix theJSF
scope andCDI
scope. – Amberjackbeans.xml
file to get CDI Bean to work ? – Hurffweb.xml
,faces-config.xml
andbeans.xml
so that bare defaults are used? – Copalmfaces-config.xml
file, but it did not solve the problem until I added thebeans.xml
, but if I removed thebeans.xml
, I got that error – Hurff/WEB-INF/lib
? – Copalmlib
folder, I just added the JSF jar file by right clicking theLibraries
section in Netbeans, but that did not make any difference since GlassFish has that jar toos – Hurffbeans.xml
was ever needed explicitly in both 4.0 and 4.1. (The application has already traversed through all Mojarra 2.2.x versions alternatively - starting from Mojarra 2.2.0 to 2.3.0-m01). – Stuppyscripts
subfolder under theresources
folder, and theresources
folder is underMETA-INF
and then at the application root using<h:outputScript />
, but I keep gettingUnable to find resource
. My structure is like this,JavaServerFaces
is the parent directory where all other folders are located, then in it, there is theresources
folder, inside theresources
folder is thescripts
sub folder where the script file is stored – Hurffresources
folder directly into the web application root. (META-INF
is meant for a standalone module in a separately packaged JAR file which finally ends up in/WEB-INF/lib
in the associated WAR). – Stuppyresources
folder in theJavaServerFaces
parent folder, and theresources
folder is then sub-divided into smaller folders for better resource organizing, in this case, I hate thescripts
sub-folder which contains a dummy javascript file. Aghh, so frustrating, I don't know what is wrong with my GS – Hurff<h:outputScript library="..." name="..." />
is going wrong. And please do not forget to hard-deploy the application at least once after these changes have been made. If the problem still persists, you may want to put a separate question. – Stuppy