galera ta estranho!!!!
Tenho essa view feita com jsf e facelets, lá em baixo tem uma tag ajax4jsf para fazer o cadastro de nome e email, entretanto e estranhamente ele persiste(to usando hibernate) só o primeiro registro que tento adicionar o segundo ele da um erro estranho e outra coisa é que fiz uns debugs aqui e me parece q na segunda vez que adiciono ele tenta carregar a página inteira denovo. to mandando os códigos abaixo.
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:vi="http://Commerce.Components/VisualComponents"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:rich="http://richfaces.ajax4jsf.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
<ui:composition>
<!-- Busca de Produtos -->
<div class="#{classbusca}">
<h1>#{titlebusca}</h1>
<h:form id="form_busca" name="form_busca">
<h:inputText id="nome" size="18" required="true" requiredMessage="Palavra Obrigatória" />
<h:commandButton id="submit" action="submit" value="submit" image="images/menu/busca.jpg" />
</h:form>
<p>Use palavras-chave para realizar a busca.</p>
<a href="busca.faces">Busca Avançada</a>
</div>
<!-- Categorias -->
<div class="#{classcategoria}">
<h1>#{titlecategoria}</h1>
<ul>
<ui:repeat value="#{itens}" var="c">
<a href="#"><li>#{c}</li></a>
</ui:repeat>
</ul>
</div>
<!-- Sistema de atendimento Online -->
<div style="text-align:center;width:180px;">
<a href="javascript:void(window.open('http://www.ecommerce.asturbo.com.br/livezilla.php','','width=600,height=550,left=0,top=0,resizable=yes,menubar=no,location=yes,status=yes,scrollbars=yes'))">
<img src="http://www.ecommerce.asturbo.com.br/image.php?id=01" width="180" height="120" border="0" alt="Atendimento Online" style="margin:20px 0 0 10px;"/>
</a>
<noscript>
<div>
<a href="http://www.ecommerce.asturbo.com.br/livezilla.php" target="_blank">Iniciar Atendimento Online</a>
</div>
</noscript>
</div>
<div id="livezilla_tracking" style="display:none"></div>
<script language="JavaScript" type="text/javascript">
<!--
var script = document.createElement("script");script.type="text/javascript";var src = "http://www.ecommerce.asturbo.com.br/server.php?request=track&output=jscript&nse="+Math.random();setTimeout("script.src=src;document.getElementById('livezilla_tracking').appendChild(script)",1);
// -->
</script>
<!-- Newsletter -->
<div class="newsletter">
<a4j:form id="newsletter" >
<h:inputText id="nome" size="19" value="#{emailInformativoMB.nome}" required="" class="input_form_lateral1" />
<h:inputText id="email" size="19" value="#{emailInformativoMB.email}" required="" class="input_form_lateral2" />
<h:commandButton id="submit" reRender="form" action="#{emailInformativoMB.cadastrarEmailInformativo}" oncomplete="alert('Teste com sucesso!')" image="images/newsletter/botao_ok.jpg" />
</h:form>
</div>
</ui:composition>
</html>
package com.as.commerce.controller;
import com.as.commerce.controller.EntityManagerFactorySingleton;
import com.as.commerce.dao.EmailInformativoDAO;
import com.as.commerce.model.EmailInformativo;
import javax.persistence.EntityManager;
public class EmailInformativoMB {
private String text;
private String nome;
private String email;
private EmailInformativo emailInformativo;
private EmailInformativoDAO emailInformativoDAO;
private EntityManager emf;
public EmailInformativoMB() {
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void cadastrarEmailInformativo() {
try {
//inicializa o manager
emf = EntityManagerFactorySingleton.getEntityManager();
//inicia a sessao
emf.getTransaction().begin();
//cria o objeto que vai ser persistido
emailInformativo = new EmailInformativo();
emailInformativo.setNome(nome);
emailInformativo.setEmail(email);
//Cria o DAO
emailInformativoDAO = new EmailInformativoDAO(emf);
//Persiste o Objeto
emailInformativoDAO.create(emailInformativo);
//Comita a transação
emf.getTransaction().commit();
} catch (Exception ex) {
//Volta a trasnação
emf.getTransaction().rollback();
System.out.println(ex.getStackTrace());
} finally {
//em qualquer hipotese fecha o manager
emf.close();
}
}
}
package com.as.commerce.dao;
import com.as.commerce.controller.EntityManagerFactorySingleton;
import com.as.commerce.model.CategoriaProduto;
import java.util.ArrayList;
public class CategoriaDAO extends GenericDAO{
public CategoriaDAO() {
emf = EntityManagerFactorySingleton.getEntityManager();
}
public ArrayList<CategoriaProduto> getCategorias() {
emf.getTransaction().begin();
ArrayList list = new ArrayList();
list = (ArrayList<CategoriaProduto>) emf.createQuery("select nome from CategoriaProduto").getResultList();
emf.getTransaction().commit();
emf.close();
return list;
}
}
Erro
HTTP Status 500 -type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.el.ELException: /WEB-INF/Components/menu_lateral.xhtml @28,53 value="#{itens}": /index.xhtml @14,190 itens="#{CategoriaDAO.categorias}": javax.faces.el.EvaluationException: com.as.commerce.dao.CategoriaDAO
root cause
javax.faces.el.EvaluationException: javax.el.ELException: /WEB-INF/Components/menu_lateral.xhtml @28,53 value="#{itens}": /index.xhtml @14,190 itens="#{CategoriaDAO.categorias}": javax.faces.el.EvaluationException: com.as.commerce.dao.CategoriaDAO
root cause
javax.el.ELException: /WEB-INF/Components/menu_lateral.xhtml @28,53 value="#{itens}": /index.xhtml @14,190 itens="#{CategoriaDAO.categorias}": javax.faces.el.EvaluationException: com.as.commerce.dao.CategoriaDAO
root cause
javax.faces.el.EvaluationException: com.as.commerce.dao.CategoriaDAO
root cause
javax.faces.el.EvaluationException: Bean: com.as.commerce.dao.CategoriaDAO, property: categorias
root cause
java.lang.reflect.InvocationTargetException
root cause
java.lang.IllegalStateException: EntityManager is closed
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_02 logs.
Se precisar eu mando mais código ai pra vcs!!!!
Se alguém puder me auxiliar valeu!!!
Valeu galera!!!!