i have implements the delete function successfully, but when i click the 'save changes' button, the tables is not automatically reload. So the table still shown the row that i have deleted.
I need to click 'clear' button instead to reload the content of the table.
@RequestMapping(value = "contactListForm", method = RequestMethod.GET)
public ModelAndView getContactListForm(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new ModelAndView("contactList");
listOfContacts = findAllContacts();
TableModel tableModel = new TableModel("contactModel", request);
tableModel.setItems(listOfContacts);
tableModel.setEditable(true);
tableModel.saveWorksheet(new WorksheetSaver() {
public void saveWorksheet(Worksheet worksheet) {
saveWorksheetChanges(worksheet);
}
});
HtmlTable htmlTable = new HtmlTable();
htmlTable.caption("Contacts Manager");
// non-fluent columns
HtmlRow htmlRow = new HtmlRow();
htmlRow.setUniqueProperty("contactId");
HtmlColumn remove = new HtmlColumn("remove");
remove.setWidth("5%");
remove.setWorksheetEditor(new RemoveRowWorksheetEditor());
remove.setTitle(" ");
remove.setFilterable(false);
remove.setSortable(false);
htmlRow.addColumn(remove);
HtmlColumn firstName = new HtmlColumn("firstName").title("First Name");
htmlRow.addColumn(firstName);
HtmlColumn lastName = new HtmlColumn("lastName").title("Last Name");
htmlRow.addColumn(lastName);
HtmlColumn email = new HtmlColumn("email");
htmlRow.addColumn(email);
HtmlColumn telephone = new HtmlColumn("telephone");
htmlRow.addColumn(telephone);
htmlRow.setSortable(true);
htmlRow.setFilterable(true);
htmlTable.setRow(htmlRow);
tableModel.setTable(htmlTable);
String html = tableModel.render();
mv.addObject("contacts", html);
return mv;
}
private void saveWorksheetChanges(Worksheet worksheet) {
logger.info("=====> ContactController.saveWorksheetChanges is invoked !"); String uniquePropertyName = WorksheetUtils.getUniquePropertyName(worksheet);
final List<String> uniquePropertyValues = WorksheetUtils.getUniquePropertyValues(worksheet);
logger.info("=====> uniquePropertyName : " + uniquePropertyName);
worksheet.processRows(new WorksheetCallbackHandler() {
public void process(WorksheetRow worksheetRow) {
if (worksheetRow.getRowStatus().equals(WorksheetRowStatus.ADD)) {
// do something to insert into table
} else if (worksheetRow.getRowStatus().equals(WorksheetRowStatus.REMOVE)) {
try {
for (String value : uniquePropertyValues) {
logger.info("=====> contact with id : " + value + " will be removed !"); serviceLocator.getContactService().batchDeleteContactById(uniquePropertyValues);
}
} catch (Exception e) {
logger.error("=====> ContactController.saveWorksheetChanges.processRows-REMOVE is error!", e);
}
} else if (worksheetRow.getRowStatus().equals(WorksheetRowStatus.MODIFY)) {
// do something to update the table
}
}
}
});
}
regards.