简体   繁体   English

Netbeans Swing Master细节示例表格删除不起作用

[英]Netbeans swing Master detail sample form delete not working

I'm using NB 7.4, JavaDb , jdk 7. 我正在使用NB 7.4,JavaDb,jdk 7。

I tried to work on this example : http://simsam7.blogspot.in/2013/06/quick-crud-application-on-netbeans-73.html 我尝试处理此示例: http : //simsam7.blogspot.in/2013/06/quick-crud-application-on-netbeans-73.html

In CRUD, CRU works good, but delete not working,and its not throwing any error also. 在CRUD中,CRU可以正常工作,但是删除不起作用,并且也不会引发任何错误。

My Code for delete button. 我的删除代码按钮。

 int[] selected = masterTable.getSelectedRows();
        List<com.fz.PurchaseOrder> toRemove = new ArrayList<com.fz.PurchaseOrder>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            com.fz.PurchaseOrder p = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(p);
            entityManager.remove(p);
        }
        list.removeAll(toRemove);

I done debug, and i think error at entityManager.remove(p). 我完成了调试,我认为在entityManager.remove(p)处出错。

INFO : Output GUI - The row in table removes/delete good, but when i refresh it shows again. 信息:输出GUI-表中的行已删除/删除良好,但是当我刷新时再次显示。

I solved my problem by this code. 我用这段代码解决了我的问题。 It works, but i'm not sure, is it the right way? 它有效,但是我不确定,这是正确的方法吗?

int[] selected = masterTable.getSelectedRows();
        List<Products> toRemove = new ArrayList<Products>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            Products p = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(p);
            entityManager.remove(p);
        }
        try {
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
        } catch (Exception e) {
        }
        list.removeAll(toRemove);

If there is a better way, please let me know. 如果有更好的方法,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM