I am inside my service and here is where I put the parameter so that I receive the id of the row I want to delete.
@Transactional
public void eliminaHerramienta(Integer idherramienta) {
try {
Herramienta p = manager.find(Herramienta.class, idherramienta);
manager.getTransaction().begin();
manager.remove(p);
manager.flush();
manager.getTransaction().commit();
} catch (Exception e) {
manager.getTransaction().rollback();
e.printStackTrace();
} finally {
manager.close();
}
}
Then I'm in the controller to do the interaction with the view which is like a requestScoped
@Transactional
public void eliminar(Integer idherramienta) {
System.out.println("entrando a eliminar alumno");
herramientaService.eliminaHerramienta(idherramienta);
}
apparently everything is great but it does not go into the method of removing the moment when I click on the button to call that action on the controller.
<p:dataTable value="#{herramientaAction.lstherramienta}" var="h"
border="1" paginator="true" rows="5">
<p:column>
<f:facet name="header">Id</f:facet>
#{h.idherramienta}
</p:column>
<p:column>
<f:facet name="header">Nombre</f:facet>
#{h.name}
</p:column>
<p:column>
<f:facet name="header">stock</f:facet>
#{h.stock}
</p:column>
<p:column>
<f:facet name="header">precio</f:facet>
#{h.precio}
</p:column>
<p:column>
<f:facet name="header">fecha vencimiento</f:facet>
#{h.fecha}
</p:column>
<p:column>
<f:facet name="header">modelo</f:facet>
#{h.modelo.descripcion}
</p:column>
<p:column>
<p:commandButton id="btn1"
action="#{herramientaAction.eliminar(h.idherramienta)}" value="eliminar" />
</p:column>
</p:dataTable>
As you can see it has the view of a datatable, I do not know what thing I have to add to work or receive that action.