0

在一个副项目上工作,试图遍历一个弹性表并提取数据。该表有一列,其中包含另一个表,该表跨越与其关联的行的行。我首先获取该数据,然后获取与其关联的行,将其填充到程序集中,然后将其存储在 arraylist 中。我的问题是当它正确提取数据时,它没有存储到数组列表中。它覆盖了前面的所有行,我不知道为什么。这是 while 循环的范围问题吗?我没有正确声明某些东西吗?代码如下

private static void submitOrder() {

    if (nullCheck()) {
        ArrayList<AssemblyLine> assemblyLines = new ArrayList<AssemblyLine>();
        HorizontalPanel hPanel = (HorizontalPanel) fTable.getWidget(fTable.getRowCount() - 1, 0);
        CheckBox cb1 = (CheckBox) hPanel.getWidget(0);
        int rowSpan = 0;
        int currentRow = 1;
        int currentAssemblyLineRow = 1;

        while (currentRow < fTable.getRowCount() - 2) {
            // get current info table and set initial data
            FlexTable currentInfoTable = (FlexTable) fTable.getWidget(currentRow, 7);
            rowSpan = fTable.getFlexCellFormatter().getRowSpan(currentRow, 7);
            AssemblyLine al = new AssemblyLine();
            ListBox assembler = (ListBox) currentInfoTable.getWidget(2, 1);
            DateBox date = (DateBox) currentInfoTable.getWidget(3, 1);
            al.setAssemblerName(assembler.getValue(assembler.getSelectedIndex()));
            al.setDate(date.getValue());
            al.setAssemblyID(Integer.parseInt(fTable.getHTML(currentRow, 0)));

            // if "use all info for lots" is checked set assembler and date
            // to that
//other data set here

            // iterate through related rows and store assemblylines in
            // database, I think the error is in here
            while (currentAssemblyLineRow < (rowSpan + currentRow)) {
                al.setQuantity(Integer.parseInt(fTable.getHTML(currentAssemblyLineRow, 5)));
                System.out.println("al.getQuantity: " + al.getQuantity());
                ListBox lb = (ListBox) fTable.getWidget(currentAssemblyLineRow, 6);
                al.setPartLotNumber(lb.getItemText(lb.getSelectedIndex()));
                System.out.println("al.getPartLotNumber: " + al.getPartLotNumber());
                assemblyLines.add(al);
                System.out.println("al.tostring: " + al.toString());
                System.out.println("a.tostring: " + assemblyLines.get(assemblyLines.size() - 1).toString());
                currentAssemblyLineRow++;
            }

            for (int k = 0; k < assemblyLines.size(); k++) {
                System.out.println("a.tostring: " + k + " " + assemblyLines.get(k).toString());
            }

            // then iterate to next infotable
            currentRow = currentRow + rowSpan;

        }

        DatabaseUtils.submitAssemblyLines(assemblyLines);
    } else {
        Window.alert("Oops! please fill out all boxes!");
    }

}

这是控制台的输出

    al.getQuantity: 1
al.getPartLotNumber: 43528
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=43528, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=43528, quantity=1]
al.getQuantity: 1
al.getPartLotNumber: H17253
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=H17253, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=H17253, quantity=1]
al.getQuantity: 1
al.getPartLotNumber: 31561414
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=31561414, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=31561414, quantity=1]
al.getQuantity: 1
al.getPartLotNumber: 001122
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=001122, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=001122, quantity=1]
al.getQuantity: 2
al.getPartLotNumber: 123456
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=123456, quantity=2]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=123456, quantity=2]
al.getQuantity: 1
al.getPartLotNumber: 103534
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=103534, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=103534, quantity=1]
al.getQuantity: 1
al.getPartLotNumber: P12345
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 0 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 1 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 2 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 3 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 4 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 5 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 6 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
al.getQuantity: 1
al.getPartLotNumber: H17253
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=H17253, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=H17253, quantity=1]
al.getQuantity: 2
al.getPartLotNumber: 001122
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=001122, quantity=2]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=001122, quantity=2]
al.getQuantity: 1
al.getPartLotNumber: P12345
al.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 0 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 1 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 2 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 3 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 4 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 5 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 6 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=12, AssemblerID=0, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 7 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 8 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
a.tostring: 9 AssemblyLine [AssemblyLineID=0, AssemblyLotNumber=0, AssemblyID=13, AssemblerID=0, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLot at 0: Assembly [assemblyLotNumber=1, assemblyID=12, name=null, partID=null, quantities=null]
AssemblyLot at 1: Assembly [assemblyLotNumber=2, assemblyID=13, name=null, partID=null, quantities=null]
AssemblyLines at 0: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 1: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 2: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 3: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 4: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 5: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 6: AssemblyLine [AssemblyLineID=7, AssemblyLotNumber=1, AssemblyID=12, AssemblerID=1, AssemblerName=John, date=Thu Aug 01 14:54:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 7: AssemblyLine [AssemblyLineID=10, AssemblyLotNumber=2, AssemblyID=13, AssemblerID=2, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 8: AssemblyLine [AssemblyLineID=10, AssemblyLotNumber=2, AssemblyID=13, AssemblerID=2, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
AssemblyLines at 9: AssemblyLine [AssemblyLineID=10, AssemblyLotNumber=2, AssemblyID=13, AssemblerID=2, AssemblerName=Blake, date=Fri Aug 02 12:00:00 PDT 2013, partLotNumber=P12345, quantity=1]
4

1 回答 1

1

您需要AssemblyLine每次通过循环分配一个新的。现在,您所做的只是一遍又一遍地添加相同的对象(每次通过循环修改它)。

ListBox assembler = (ListBox) currentInfoTable.getWidget(2, 1);
DateBox date = (DateBox) currentInfoTable.getWidget(3, 1);

while (currentAssemblyLineRow < (rowSpan + currentRow)) {
    AssemblyLine al = new AssemblyLine();
    al.setAssemblerName(assembler.getValue(assembler.getSelectedIndex()));
    al.setDate(date.getValue());
    al.setAssemblyID(Integer.parseInt(fTable.getHTML(currentRow, 0)));
    // rest of loop body goes here (current code)
}
于 2013-08-01T22:13:26.677 回答