try
{
UserVO user = (UserVO) panel.getEntity();
RoleVO role = new RoleDAO().getById(form.getId());
if(user.getProfile().getLdapGroup() == null && user.getProfile().getRole() == null || user.getProfile().getRole().isAdmin() != role.isAdmin()) {
user.getProfile().getUsergroups().clear();
user.getProfile().getUsergroups().add(role.getDefaultUsergroup());
user.getProfile().setDefaultUsergroup(role.getDefaultUsergroup());
}
user.getProfile().setRole(role);
if(role.isAdmin())
user.setPerson(null);
}
catch (HibernateException e)
{
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("default.error.invalidEntity", new Integer(form.getId())));