Delete method is not called when I click on a commandButton

Asked

Viewed 203 times

2

I have an delete button that sits inside a column of dataTable and when I click on the same the method that is responsible for the user’s deletion is not called.

datatable:

<p:dataTable value="#{usuarioBean.listaUsuario}" id="usuarioTable"
var="usuario" style="" emptyMessage="Nenhuma Usuário Encontrado. "
rows="5" paginator="true" paginatorPosition="bottom">

Delete button:

<b:commandButton icon="glyphicon glyphicon-remove" value=""
look="danger" style="margin-left:10px" ajax="true"
update="frmPrin" title="Excluir" actionListener="#{usuarioBean.excluir(usuario)}">
</b:commandButton>

Delete method in MB:

public void excluir(Usuario usuario) {
        System.err.println("Metodo Excluir");

        try {
            UsuarioDAO usuarioDAO = new UsuarioDAO();
            usuarioDAO.excluir(usuario);

            FacesUtil.adicionarMsgInfo("Usuario excluido com sucesso");
            usuario = new Usuario();
            listarUsuarios();
        } catch (RuntimeException e) {
            FacesUtil.adicionarMsgErro("Erro ao excluir usuário");
            e.printStackTrace();
        }
    }

Exclude method on DAO:

public void excluir(Usuario usuario) {
        System.out.println("<METODO EXCLUIR CHAMADO");
        Session sessao = HibernateUtil.getSessionFactory().openSession();
        Transaction transacao = null;
        try {
            transacao = sessao.beginTransaction();
            sessao.delete(usuario);
            transacao.commit();
        } catch (RuntimeException ex) {

            throw ex;
        } finally {
            sessao.close();
        }
    }

The scope of the MB is @SessionScoped

  • actionListener="#{usuarioBean.excluir(usuario} is missing a ) , put and forehead again.

  • It was an error in the question only, the code was right and yet the method is not being called

  • tried to add process="@this" to the button?

  • I’m using BootsFaces no process to put on buttons

  • This component is within the same form?

  • Yes, I tried everything and could not solve I think it is a problem with Bootsfaces

  • Because when I use Primefaces it works

  • @Diegoaugusto, already tried to use only action?

  • 1

    Put ajax=false in commandButton.

  • @Douglas If you want to answer, this is a solution. I had forgotten to answer this question after troubleshooting the error

Show 5 more comments

1 answer

0

In his commandButton change the ajax:

ajax="false"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.