removing Items from datasource with a loop

I have three tables in my Editor form (1) Available PurchaseRequisition 2) Selected PurchaseRequisition and 3) PurchaseOrder Master-detail.

When I select one or more Purchase Requisition from table 1, it is included in table 2 and at the same time the Items from the Purchase requisition in added to table 3 which is collection of Purchase Order.

Now, When I remove a Purchase Requisition from table 2, I invoke the following method to delete all children Line items from Purchase order Lines (collection), of course other line items belonging to some other Purchase requisition will remain there. however, it does delete one of two line items only.



    public void onRemovePr(Component source) {
        if (purchaseOrderPrDs.getItem() != null) {
            if( purchaseOrderLineDs.size()> 0){
                PurchaseRequisition pr = purchaseOrderPrDs.getItem().getPurchaseRequisition();
                Collection<PurchaseOrderLine> lineList = purchaseOrderLineDs.getItems();

                //Delete PO Line where the PR is deleted
                for (PurchaseOrderLine line : lineList) {
                    for(PurchaseOrderLine poLine : purchaseOrderLineDs.getItems()) {
                        if (line.getPurchaseRequisition().equals(poLine.getPurchaseRequisition())) {
                            if(poLine.getPurchaseRequisition().equals(pr))
                                    purchaseOrderLineDs.removeItem(line);
                           
                    }
                    }
               }
               
                purchaseOrderPrDs.removeItem(purchaseOrderPrDs.getItem());
            }
        }
    }

Thanks for your help.

Hi,
Could you share a little demo project?
And “step-by-step” guide on how to reproduce the problem?