Depois de Criar um formulário em JSF .
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Cadastro de Produtos</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Nome :" for="nome" />
<h:inputText id="nome" value="#{produtoBean.produto.nome}" />
<h:outputLabel value="Descricao :" for="desc" />
<h:inputTextarea id="desc" value="#{produtoBean.produto.descricao}" />
<h:outputLabel value="Preco :" for="preco" />
<h:inputText id="preco" value="#{produtoBean.produto.preco}" />
<h:commandButton value="Gravar" action="#{produtoBean.grava}" />
</h:panelGrid>
</h:form>
</h:body>
</html>
e depois criar o Managed Bean.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class ProdutoBean {
private Produto produto = new Produto();
public void grava() {
System.out.println("Gravando produto no banco de dados ... ");
System.out.println("Nome: " + this.produto.getNome());
System.out.println("Descrição: " + this.produto.getDescricao());
System.out.println("Preço: " + this.produto.getPreco());
this.produto = new Produto(); // limpando os campos
}
public Produto getProduto() {
return this.produto;
}
}
tentei gravar o formulario , e o seguinte erro apareceu:
Target Unreachable, identifier ‘produtoBean’ resolved to null,
estou seguindo oque foi dito na apostila e não consigo entender o porque desse erro.