@Override public void actionSave() { List<User> editItems = new ArrayList<User>(); for (int index = 0; index < dataList.size(); index++) { if (isEditModeRow(index)) { editItems.add(dataList.get(index)); } } Collection<User> foundUserList = new ArrayList<User>(); User existedUser = new User(); for (User editItem : editItems) { String hash = Util.createPasswordHash("MD5", Util.BASE64_ENCODING, null, null, editItem.getPassword()); editItem.setPassword(hash); if (editItem.getId() == null) { existedUser.setUsername(editItem.getUsername()); foundUserList = userDAO.get(existedUser); if (foundUserList.isEmpty()) { try { // id=null stand for new added entry userDAO.persist(editItem); } catch (Exception e) { ToolSet.setErrorMessage(e.getMessage() + " Cause: " + e.getCause()); e.printStackTrace(); return; } } else { String message = "Input user name " + editItem.getUsername() + " exists in database, duplicated is not allowed"; ToolSet.setErrorMessage(message); return; } } else { try { // otherwise, it is existing entry, update it. userDAO.update(editItem); } catch (Exception e) { ToolSet.setErrorMessage(e.getMessage() + " Cause: " + e.getCause()); e.printStackTrace(); return; } } } // reload data. super.actionSave(); usersAssociatedRoleGroupEditable = false; }
public void actionRefresh() { searchExample = new User(); usersAssociatedRoleGroupEditable = false; ToolSet.resetErrorMessage(); super.actionRefresh(); }