Reputation: 31
I have a table with the options of delete and edit. When I clicked the delete button, the data does not not disappear. Then when I click refresh on my browser, and the information is deleted.
What is wrong?
<p:dataTable id="tabla2" value="#{b_rep.tabla}" var="o" widgetVar="56" style="width: 600px;" editable="true">
<p:ajax event="rowEdit" listener="#{b_rep.onEdit}" />
<p:ajax event="rowEditCancel" listener="#{b_rep.onCancel}" />
<f:facet name="header">Información subida</f:facet>
<p:column headerText="Punto de venta" filterBy="#{o.nombre}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{o.nombre}" />
</p:column>
<p:column headerText="Fecha" filterBy="#{o.fecha}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Fecha"/>
</f:facet>
<h:outputText value="#{o.fecha}">
<f:convertDateTime pattern="dd-MM-yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Opc" style="width:60px">
<p:rowEditor></p:rowEditor>
</p:column>
</p:dataTable>
This is the method that deletes information from the table:
public void onCancel(RowEditEvent event) {
try {
rep_struct change = (rep_struct) event.getObject();
BD bd = new BD();
Connection con = bd.Conectar(url);
String sql = "DELETE FROM ventas";
sql += " WHERE codpv=?";
sql += " AND fecha=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, change.getPdv());
ps.setDate(2, new java.sql.Date(change.getFecha().getTime()));
ps.executeUpdate();
ps.close();
//cargar_tabla();
tabla.remove((rep_struct) event.getObject());
FacesMessage msg = new FacesMessage("Item Borrado");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (SQLException ex) {
Logger.getLogger(rep_bean.class.getName()).log(Level.SEVERE, null, ex);
}
}
Upvotes: 1
Views: 179
Reputation: 104
<p:ajax event="rowEdit" listener="#{b_rep.onEdit}" update="tabla2"/>
<p:ajax event="rowEditCancel" listener="#{b_rep.onCancel}" update="tabla2"/>
you need to update the datatable
Upvotes: 1