System error:
Error message:
Caused by: javax.el.PropertyNotFoundException: /index.xhtml @ 22.72 value="# {ClientBean.client.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>
Systemscreenwitherror: