// get the user
SecUser anUser = getSelectedUser();
// check if the item is newly checked. If so we cannot
// found it in the SecUserrole-table
SecUserrole anUserRole = getSecurityService().getUserroleByUserAndRole(anUser, aRole);
// if new, we make a newly Object
if (anUserRole == null) {
anUserRole = getSecurityService().getNewSecUserrole();
anUserRole.setSecUser(anUser);
anUserRole.setSecRole(aRole);
}
try {
// save to DB
getSecurityService().saveOrUpdate(anUserRole);
} catch (DataAccessException e) {
ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());
}
} else if (cb.isChecked() == false) {
// Get the role object by casting
SecRole aRole = (SecRole) listitem.getAttribute("data");
// get the user
SecUser anUser = getSelectedUser();
// check if the item is newly checked. If so we cannot
// found it in the SecUserrole-table
SecUserrole anUserRole = getSecurityService().getUserroleByUserAndRole(anUser, aRole);
if (anUserRole != null) {
// delete from DB
getSecurityService().delete(anUserRole);
}