Estou criando uma aplicação de teste com JSF e Primefaces, mas estou com problemas para fazer um update em uma tabela do banco de dados.
Estou pegando o erro de NullPointerException ao dar o update (estou usando hibernate).
Esta é a minha view:
alterar.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Alterar Plataforma</title>
</h:head>
<h:body>
<p:panel header="Alterar Plataforma">
<h:form>
<p:growl />
<p:fieldset legend="Dados da Plataforma">
<p:outputLabel value="Descrição" for="descPlataforma" />
<p:inputText id="descPlataforma" required="true" value="#{plataformaBean.plataforma.descPlataforma}"/>
</p:fieldset>
<p:commandButton value="Alterar" action="#{plataformaBean.altera}">
<f:setPropertyActionListener target="#{plataformaBean.plataforma}" value="#{plataforma}" />
</p:commandButton>
</h:form>
</p:panel>
</h:body>
</html>
E o meu ManagedBean:
PlataformaBean
@ManagedBean
@RequestScoped
public class PlataformaBean implements Serializable{
private Plataforma plataforma;
public Plataforma getPlataforma() {
if(plataforma == null){
plataforma = new Plataforma();
}
return plataforma;
}
public void setPlataforma(Plataforma plataforma) {
this.plataforma = plataforma;
}
public List<Plataforma> getPlataformas() throws Exception{
return new PlataformaDao().findAll();
}
public String inserePlataforma() {
new PlataformaDao().salvar(plataforma);
return "lista";
}
public String remove() {
new PlataformaDao().excluir(plataforma.getIdPlataforma());
return "lista";
}
public String altera() {
System.out.println(plataforma.getDescPlataforma()); // aqui ocorre o NullPointerException
// new PlataformaDao().alterar(plataforma);
return "lista";
}
}