Después de cambiar @ManagedBean a @Named: javax.el.PropertyNotFoundException: Destino inalcanzable, el identificador 'persona' se resolvió como nulo [duplicado]
Esta pregunta ya tiene una respuesta aquí:
Identificar y resolver javax.el.PropertyNotFoundException: Target inalcanzable 12 respuestas Solo estoy probando esta página JSF, así que no configuro elaction
atributo en el<h:commandButton/>
. Este es un formulario muy simple con 3 cuadros de entrada para Nombre, Apellido y Correo electrónico, y un botón llamado Guardar. Cada vez que hago clic en ese botón, recibo este error
javax.el.PropertyNotFoundException: /index.xhtml @19,106 value="#{person.firstName}": Target Unreachable, identifier 'person' resolved to null
pero si anoto mi JavaBean@ManagedBean
, entonces el formulario pasa bien, pero cada vez que vuelvo a usar@Named
Bean, recibo ese error nuevamente. He intentado algunas de las sugerencias que encontré en este sitio, como reiniciar el servidor, verificar la presencia de los captadores, pero no sirvieron de nada.
<?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>
Esta es mi clase JavaBean
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;
}
}
Este es elweb.xml
archivo
<?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>