Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding new row as first row in af:table

ChristianM0147May 6 2024 — edited May 6 2024

Hello fellow Developers,

im currently Developing with JDeveloper Version 12.2.1.4.0.

I have the requirement to read a value of an inputtext and create a new row to an af:table compononent with that value. It should be checked if the value is already inserted in the table, if thats the case the value should not be added again. The issue i have is that the new row should be on top of the list and i can't achieve this.

This is my code:

           public void createNewRowInBarcodeTable(ValueChangeEvent valueChangeEvent) {
        DCIteratorBinding dcIter = ADFUtils.findIterator("ShZmlProbenAmvProbenView1Iterator");
        if (barcodeInputField.getValue() != null && !barcodeInputField.getValue()
                                                                      .toString()
                                                                      .isEmpty()) {
            ViewObject probenVO = dcIter.getViewObject();

            RowSetIterator rsi = probenVO.createRowSetIterator(null);
            // Prüfen ob es diesen Barcode bereits in der Tabelle gibt, falls ja return
            while (rsi.hasNext()) {
                Row barcodesRow = rsi.next();
                
                Long longBarcodeInTable = (Long) barcodesRow.getAttribute("Barcode");
                BigInteger bigIntegerBarcodeInTable = BigInteger.valueOf(((longBarcodeInTable)).longValue());
                BigInteger bigIntegerBarcodeInputField2 = (BigInteger) barcodeInputField.getValue();
                if (bigIntegerBarcodeInputField2.compareTo(bigIntegerBarcodeInTable) == 0) {
                    rsi.closeRowSetIterator();
                    return;
                }
            }
            rsi.closeRowSetIterator();
            
            Row newProbenRow = dcIter.getNavigatableRowIterator().createRow();
            newProbenRow.setAttribute("Barcode", barcodeInputField.getValue());
            
            Row firstRow = dcIter.getNavigatableRowIterator().first();
            int firstRowIndex = dcIter.getNavigatableRowIterator().getRangeIndexOf(firstRow);
            
            dcIter.getNavigatableRowIterator().insertRowAtRangeIndex(firstRowIndex, newProbenRow);
            dcIter.setCurrentRowWithKey(newProbenRow.getKey().toStringFormat(true));
            
            probenVO.executeQuery();
        }
        
        barcodeInputField.resetValue();
        AdfFacesContext.getCurrentInstance().addPartialTarget(barcodeInputField);
        
        setFocus("pt1:it14");
    }

i also tried setting the index directly to 0 like:

            dcIter.getNavigatableRowIterator().insertRowAtRangeIndex(0, newProbenRow);

But that also does not work.

The values always get inserted in order.

For example if i read 1,2,3,4,5 in that order, the values appeare like that but i want the order to be descending: 5,4,3,2,1. (newest number should always be on top)

The rows that i create are entitybased viewObjects with an ID (database sequence) and i also tried to just order the ID in the viewObject in descending order but that also does not work while inserting the values.

If i inserted the values and load the page again, the order set in the ViewObject work but only as long as i dont insert new values.

If i try this it gets pretty wild, for example if i insert 1,2,3,4,5 again. Refresh the Page. The values are in a descending order. But if i try to insert new values they shift the already inserted values like this:

for example i insert 6,7,8,9:

The order in the table is: 6,7,8,9,1,2,3,4,5

If i refresh the page again, the Order is again descending like i want.

So the problem only persists while inserting.

This post has been answered by Timo Hahn on May 8 2024
Jump to Answer
Comments
Post Details
Added on May 6 2024
9 comments
519 views