I have a table that consists of rows of reports. A back bean method that is tied to a check box value change event is getting the row IDs and populating an array (rowsToBeRemoved) with this IDs. Another method gets this array and removes the object from reportlist class:
ObjectListDataProvider reportList = new ObjectListDataProvider();
List<RowKey> rowsToBeRemoved=new ArrayList();
Integer rowsToBeRemovedIndex = 0;
for(RowKey rowToBeRemoved:rowsToBeRemoved){
try {
System.out.println("rowToBeRemoved.toString()" + rowToBeRemoved.toString()); // outputs: rowToBeRemoved.toString()RowKey[0]
Report report = (Report) reportList.getObject(rowToBeRemoved);
System.out.println("report.getId()" + report.getId()); //outputs: report.getId()199|
Query resultQuery = queryGeneration(report.getId());
List<String> dropTableQueries = resultQuery.getResultList(); // generated the queries to drop r tables
for(int i=0; i<dropTableQueries.size(); i++){
String aDropTableQuery;
aDropTableQuery = dropTableQueries.get(i);
System.out.println("adroptableuery" + aDropTableQuery);// get single drop table query. outputs adroptableueryDROP TABLE r_199_0
entityManager.createNativeQuery(aDropTableQuery);
System.out.println("entitymanager dropTableQueries is invoked");//OK
reportList.removeObject(rowToBeRemoved);
System.out.println("removeObject");//OK
if (reportList.isRemoved(rowToBeRemoved)){
System.out.println("object removed");//OK
}
reportList.commitChanges();
System.out.println("commitchanges");//OK
}
reportJpaController.delete(report);
reportList.removeRow(rowToBeRemoved);
reportList.commitChanges();
analyzerResultService.drop(report.getId().longValue());
//rowsToBeRemoved.remove(rowsToBeRemovedIndex);
} catch (Exception e) {
error("Cannot delete report with row key " + rowToBeRemoved + e);
}
The code executes fine, removes the object from the reportlist but after that my table brings up a mixed reportlist. If I refresh the page it brings the reportlist in correct order, otherwise it doesn't. And if I try to delete a row in the mixed state it deletes the report as if it is in correct order, thus ending with deleting the wrong report. I hope I could explained.. What am I doing wrong?
I think this is similar to what you're looking for: How to refresh entire JSF page from the backing bean
This doesnt just refresh one part of the page though, but the full page.