-1
System with error:
Error message:
Caused by: javax.el.Propertynotfoundexception: /index.xhtml @22,72 value="#{Clientebean.cliente.name}": Target Unreachable, Identifier 'Clientebean' resolved to null at com.sun.faces.facelets.el.TagValueExpression.getType(Tagvalueexpression.java:100) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(Htmlbasicinputrenderer.java:95) at javax.faces.Component.UIInput.getConvertedValue(Uiinput.java:1045) at javax.faces.Component.UIInput.validate(Uiinput.java:975) at javax.faces.Component.UIInput.executeValidate(Uiinput.java:1248) at javax.faces.Component.UIInput.processValidators(Uiinput.java:712) at javax.faces.Component.UIComponentBase.processValidators(Uicomponentbase.java:1258) at javax.faces.Component.UIForm.processValidators(Uiform.java:253) at javax.faces.Component.UIComponentBase.processValidators(Uicomponentbase.java:1258) at javax.faces.Component.UIComponentBase.processValidators(Uicomponentbase.java:1258) at javax.faces.Component.UIViewRoot.processValidators(Uiviewroot.java:1195) at com.sun.faces.lifecycle.Processvalidationsphase.execute(Processvalidationsphase.java:76) ... 24 more Caused by: javax.el.Propertynotfoundexception: Target Unreachable, Identifier 'Clientebean' resolved to null at org.apache.el.parser.Astvalue.getTarget(Astvalue.java:74) at org.apache.el.parser.Astvalue.getType(Astvalue.java:58) at org.apache.el.ValueExpressionImpl.getType(Valueexpressionimpl.java:168) at com.sun.faces.facelets.el.TagValueExpression.getType(Tagvalueexpression.java:98) ... 35 more
Controller Bean
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
/**
*
* @author alunoti
*/
import dao.ClienteDAO;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import modelo.Cliente;
/**
*
* @author andii
*/
@Named(value = "ClienteBean")
@SessionScoped
public class ClienteBean implements Serializable {
@EJB
private ClienteDAO clienteDAO;
private Cliente cliente = new Cliente();
private List<Cliente> clientes;
public void novo(){
cliente = new Cliente();
}
public void gravar() {
FacesContext context = FacesContext.getCurrentInstance();
boolean resultado = clienteDAO.gravar(cliente);
if (resultado) {
cliente = new Cliente();
context.addMessage(null, new FacesMessage("Cliente gravado com sucesso"));
} else {
context.addMessage(null, new FacesMessage("Falha ao gravar cliente!"));
}
}
public void selecionar(ActionEvent evento) {
Long codigo = (Long) evento.getComponent().getAttributes().get("codigo");
cliente = clienteDAO.selecionar(codigo);
}
public void remover() {
FacesContext context = FacesContext.getCurrentInstance();
boolean resultado = clienteDAO.remover(cliente);
if (resultado) {
cliente = new Cliente();
context.addMessage(null, new FacesMessage("Cliente removido com sucesso"));
} else {
context.addMessage(null, new FacesMessage("Falha ao remover cliente!"));
}
}
//Getters e Setters
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
public List<Cliente> getClientes() {
clientes = clienteDAO.listar();
return clientes;
}
public void setClientes(List<Cliente> clientes) {
this.clientes = clientes;
}
}
index.xhtml
<?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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form id="dadosCliente">
<fieldset style="width: 350px">
<legend>Novo cliente</legend>
<h:commandButton value="Novo" action="#{ClienteBean.novo}" />
</fieldset>
<fieldset style="width: 350px">
<legend>Dados do cliente</legend>
<h:panelGrid columns="4">
<h:outputText value="Nome" />
<h:inputText value="#{ClienteBean.cliente.nome}" />
<h:commandButton value="Gravar" action="#{ClienteBean.gravar}" />
<h:commandButton value="Remover" action="#{ClienteBean.remover}" rendered="#{ClienteBean.cliente.codigo > 0}" />
</h:panelGrid>
</fieldset>
</h:form>
<h:form>
<fieldset style="width: 350px">
<legend>Clientes</legend>
<h:dataTable value="#{ClienteBean.clientes}" var="cliente" border="1">
<h:column>
<f:facet name="header"><h:outputText value="CODIGO" /></f:facet>
<h:outputText value="#{Cliente.codigo}" />
</h:column>
<h:column>
<f:facet name="header"><h:outputText value="NOME" /></f:facet>
<h:outputText value="#{Cliente.nome}" />
</h:column>
<h:column>
<h:commandButton value="Selecionar" actionListener="#{ClienteBean.selecionar}">
<f:attribute name="codigo" value="#{Cliente.codigo}" />
<f:ajax render=":dadosCliente" execute="@this" />
</h:commandButton>
</h:column>
</h:dataTable>
</fieldset>
</h:form>
</h:body>
</html>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="crudPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>modelo.Cliente</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3307/bancoteste?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
Devo alter no Clientebean.java: Sessionscoped paraViewScoped ??
– alexjosesilva
@alexjosesilva this will work. But maybe it’s not what you want. If you want to keep the
@SessionScoped
you should open an HTTP session before trying to access the page in question– igventurelli
did not solve.. is still coming out the same mistake!
– alexjosesilva
After all what error is this: Target Unreachable, Identifier 'Clientebean' resolved to null ?
– alexjosesilva
@alexjosesilva ah cara, agora que vi. In XHTML you should reference your Managedbean with the first letter with lowercase letter. So:
value="#{clienteBean.cliente.nome}
and notvalue="#{ClienteBean.cliente.nome}
– igventurelli
@alexjosesilva is the
NullPointerException
of the JSF.– igventurelli
Let’s go continue this discussion in chat.
– igventurelli