Metodo excluir em java web

Java

15/09/2015

Alguem poderia me ajudar não estou conseguido fazer o metodo excluir a onde estou errado no meu codigo.
metodo excluir na minha bean
public void excluir(){
		 try{
		    AtendenteDAO dao = new AtendenteDAO();
		    dao.remove(atendente); 
		    System.out.println("Excluindo Atendente com Sucesso");
	    }catch(Exception e){
			e.getMessage();
			e.getStackTrace();
		}
	 } 

minha DAO
package br.com.sistema_oficina_mecanica.DAO;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import br.com.sistema_oficina_mecanica.entity.AtendenteEntity;


public class AtendenteDAO {

    protected EntityManager entityManager;
    
    public AtendenteDAO() {
        entityManager = getEntityManager();
    }
 
    private EntityManager getEntityManager() {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("sistema_oficina_mecanica");
        if (entityManager == null) {
            entityManager = factory.createEntityManager();
        }
        return entityManager;
    }
 
    public AtendenteEntity getById(final int id) {
        return entityManager.find(AtendenteEntity.class, id);
    }
 
    @SuppressWarnings("unchecked")
    public List<AtendenteEntity> findAll() {
        return entityManager.createQuery("FROM " + AtendenteEntity.class.getName()).getResultList();
    }
 
    public void persist(AtendenteEntity atendente) {
        try {
            entityManager.getTransaction().begin();
            entityManager.persist(atendente);
            entityManager.getTransaction().commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            entityManager.getTransaction().rollback();
        }
    }
 
    public void merge(AtendenteEntity atendente) {
        try {
            entityManager.getTransaction().begin();
            entityManager.merge(atendente);
            entityManager.getTransaction().commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            entityManager.getTransaction().rollback();
        }
    }
 
    public void remove(AtendenteEntity atendente) {
        try {
            entityManager.getTransaction().begin();
            atendente = entityManager.find(AtendenteEntity.class, atendente.getId());
            entityManager.remove(atendente);
            entityManager.getTransaction().commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            entityManager.getTransaction().rollback();
        }
    }
 
    public void removeById(final int id) {
        try {
        	AtendenteEntity atendente = getById(id);
            remove(atendente);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}


meu 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" >
<h: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>Listar Atendentes</title>
	    <link rel="shortcut icon" type="image/x-icon" href="resourses/img/favicon.ico"/> 
	    <link href="resourses/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	    <link href="resourses/css/stylo.css" rel="stylesheet" type="text/css" />
	    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js" xml:space="preserve"></script>
	    <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" xml:space="preserve"></script>
	    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
	    <script src="resourses/js/script.js"></script>
	  </h:head>
<h:body>
    <ui:include src="includes/cabecalho.xhtml" /><!-- cabecalho-->
    <br /><br /><br /><br /><br />
    <div class="container-fluid">
	<div class="row-fluid">
    <div class="span9">
	<h:form>
            <div class="row-fluid">
              <div class="span12">
                 <div class="well">
                 <center><h2 style="font-family: 'Arial', sans-serif; color:#1c99db;">Listar Atendentes</h2></center><hr />
                 <div class="form-horizontal"> 
		                 <table class="table table-striped">
		                  <thead>
						    <tr>
						     <th>Id</th>
						     <th>Nome</th>
						     <th>E-mail</th>
						     <th>Ação</th>
						    </tr>
						  </thead>
		             		<ui:repeat var="atendente" value="#{atendenteMB.atendentes}">
							  <thead>
							    <tr>
							      <td>#{atendente.id}</td>
							      <td>#{atendente.nome}</td>
							      <td>#{atendente.email}</td>
							      <td>
								      <a class="btn btn-warning" href="" ><i class="icon-edit"></i>  Editar </a>
								     
								      <h:commandButton id="remove" actionListener="#{atendenteMB.excluir(atendente.id)}"  class="btn btn-danger" value="Excluir"/>
								      
							      </td>
							    </tr>
							  </thead>
							  </ui:repeat>
						 </table>
				 </div> 
                 </div>
                </div>
              </div>
                <div class="row-fluid"><!--  Button -->
      			<div class="span12">
        			<div class="well">
                		<fieldset>
                  			<br />
                  			<a class="btn btn-success" href="cadastrarAtendente.jsf" ><i class="icon-backward"></i> Voltar</a>    
                		</fieldset>
            		</div>
        		</div>
    		  </div>  
    		</h:form>
          </div>
        </div>
       </div>
      <ui:include src="includes/rodape.xhtml" /><!-- rodapé -->   
  </h:body>
</h:html>
Michel Santos

Michel Santos

Curtidas 0
POSTAR