use of org.webpieces.router.api.actions.FlashAndRedirect in project webpieces by deanhiller.
the class CrudTestController method postSaveUser.
public Redirect postSaveUser(UserTestDbo entity, String password) {
if (password == null) {
Current.validation().addError("password", "password is required");
} else if (password.length() < 4) {
Current.validation().addError("password", "Value is too short");
}
if (Current.validation().hasErrors()) {
log.info("page has errors");
FlashAndRedirect redirect = new FlashAndRedirect(Current.getContext(), "Errors in form below");
//make sure secure fields are not put in flash cookie!!!
redirect.setSecureFields("password");
redirect.setIdFieldAndValue("id", entity.getId());
return Actions.redirectFlashAll(ADD_USER_PAGE, EDIT_USER_PAGE, redirect);
}
Current.flash().setMessage("User successfully saved");
Em.get().merge(entity);
Em.get().flush();
return Actions.redirect(HibernateRouteId.LIST_USERS);
}
use of org.webpieces.router.api.actions.FlashAndRedirect in project webpieces by deanhiller.
the class CrudTestController method postSaveUserForMultiSelect.
public Redirect postSaveUserForMultiSelect(UserTestDbo entity, List<Role> selectedRoles, String password) {
if (password == null) {
Current.validation().addError("password", "password is required");
} else if (password.length() < 4) {
Current.validation().addError("password", "Value is too short");
}
if (Current.validation().hasErrors()) {
log.info("page has errors");
FlashAndRedirect redirect = new FlashAndRedirect(Current.getContext(), "Errors in form below");
//make sure secure fields are not put in flash cookie!!!
redirect.setSecureFields("entity.password");
redirect.setIdFieldAndValue("id", entity.getId());
return Actions.redirectFlashAll(ADD_USER_PAGE, HibernateRouteId.MULTISELECT, redirect);
}
Current.flash().setMessage("User successfully saved");
Em.get().merge(entity);
Em.get().flush();
return Actions.redirect(HibernateRouteId.LIST_USERS);
}
use of org.webpieces.router.api.actions.FlashAndRedirect in project webpieces by deanhiller.
the class ScopesController method postSaveUser.
//very typical post for adding user to database
public Redirect postSaveUser(UserDto user) {
if (user.getFirstName().length() < 3) {
Current.validation().addError("user.firstName", "First name must be more than 2 characters");
}
//the form with what the user typed in along with errors
if (Current.validation().hasErrors()) {
Current.flash().setMessage("Errors in form below");
FlashAndRedirect redirect = new FlashAndRedirect(Current.getContext(), "Errors in form below");
redirect.setIdFieldAndValue("id", user.getId());
return Actions.redirectFlashAll(ScopesRouteId.ADD_USER, ScopesRouteId.EDIT_USER, redirect);
}
Current.flash().setMessage("User successfully saved");
Current.flash().keep();
return Actions.redirect(ScopesRouteId.LIST_USER);
}
use of org.webpieces.router.api.actions.FlashAndRedirect in project webpieces by deanhiller.
the class CrudUserController method postSaveUser.
public Redirect postSaveUser(@UseQuery("findByIdWithRoleJoin") UserDbo entity, List<RoleEnum> selectedRoles, String password) {
//need to figure out how to do i18n for the messages in that case
if (password == null) {
Current.validation().addError("password", "password is required");
} else if (password.length() < 4) {
Current.validation().addError("password", "Value is too short");
}
if (entity.getFirstName() == null) {
Current.validation().addError("entity.firstName", "First name is required");
} else if (entity.getFirstName().length() < 3) {
Current.validation().addError("entity.firstName", "First name must be more than 2 characters");
}
//the form with what the user typed in along with errors
if (Current.validation().hasErrors()) {
log.info("page has errors");
FlashAndRedirect redirect = new FlashAndRedirect(Current.getContext(), "Errors in form below");
//make sure secure fields are not put in flash cookie!!!
redirect.setSecureFields("entity.password");
redirect.setIdFieldAndValue("id", entity.getId());
return Actions.redirectFlashAll(GET_ADD_USER_FORM, GET_EDIT_USER_FORM, redirect);
}
Current.flash().setMessage("User successfully saved");
Current.flash().keep();
List<UserRole> roles = entity.getRoles();
for (UserRole r : roles) {
Em.get().remove(r);
}
roles.clear();
for (RoleEnum r : selectedRoles) {
UserRole role = new UserRole(entity, r);
Em.get().persist(role);
}
Em.get().merge(entity);
Em.get().flush();
return Actions.redirect(CrudUserRouteId.LIST_USERS);
}
Aggregations