1
resposta

jsf

 javax.el.PropertyNotFoundException: /livros.xhtml @21,67 action="#{livroBean.gravar}": Target Unreachable, identifier 'livroBean' resolved to null
package br.com.caelum;

import javax.annotation.ManagedBean;

@ManagedBean
public class LivroBean {


        public void gravar(){

            System.out.println("gravando");
        }


}

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">

<h:body>
<h1>Novo livro</h1>
  <h:form>

  <fieldset>
  <legend>Dados do livro</legend>
   <h:panelGrid columns="2">
        <h:outputLabel value="Titulo" for="titulo"/>
        <h:inputText id= "titulo"/>
        <h:outputLabel value="ISBN" for="isbn"/>
        <h:inputText id= "isbn"/>
        <h:outputLabel value="Preço" for="preco"/>
        <h:inputText id= "preco"/>
        <h:outputLabel value="Data de Lançamento" for="dtlancamento"/>
        <h:inputText id= "dtlancamento"/>
        <h:commandButton value = "Gravar" action="#{livroBean.gravar}"/>
        </h:panelGrid>    
    </fieldset>

  </h:form>
 </h:body>

</html>
1 resposta

Olá,

O seu bean está nulo. Você deve inicializar o mesmo antes de usa-lo. Outra coisa é você definir o escopo do seu bean, seja de requisição, sessão...

Té mais,