use of org.springframework.validation.ObjectError in project spring-thymeleaf-simplefinance by heitkergm.
the class ChangePasswordAction method processRegisterAction.
/**
* Process change password action.
*
* @param changepwd the change password form data
* @param res the res
* @param model the model
* @param request the request
* @return the string
*/
@Transactional
@RequestMapping(value = "/changepwd", method = RequestMethod.POST)
public String processRegisterAction(@Valid @ModelAttribute("changepwd") final ChangePwd changepwd, final BindingResult res, final Model model, final HttpServletRequest request) {
if (res.hasErrors()) {
model.addAttribute("changepwd", changepwd);
model.addAttribute("tzones", context.getBean("tzones"));
return "changepwd";
}
// check the current password, etc.
String userName = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername();
List<LoginUser> users = userRepository.findByUserName(userName);
LoginUser user = users.get(0);
if (!user.checkpw(changepwd.getCurrentPassword())) {
final ObjectError objErr = new ObjectError("User", messageSource.getMessage("changepwd.currpwd.bad", null, request.getLocale()));
res.addError(objErr);
model.addAttribute("changepwd", changepwd);
model.addAttribute("tzones", context.getBean("tzones"));
return "changepwd";
}
// modify user bean
user.setPassword(changepwd.getPassword());
user.setTzone(changepwd.getTzone());
userRepository.save(user);
// logout
try {
request.logout();
} catch (ServletException se) {
LOG.info("Servlet exception upon logout " + se.getMessage());
}
return "redirect:/main";
}
use of org.springframework.validation.ObjectError in project bitcampSCOpen2017 by ryuyj.
the class MemberRegisterController method submit.
@RequestMapping(method = RequestMethod.POST)
public String submit(RegisterRequest registerRequest, BindingResult bindingResult, RedirectAttributes redirectAttributes, HttpServletRequest request) throws Exception {
if (bindingResult.hasErrors()) {
List<ObjectError> list = bindingResult.getAllErrors();
for (ObjectError e : list) {
logger.error("ObjectError : " + e);
}
throw new Exception("회원가입 실패");
}
// 업로드 폴더 시스템 물리적 경로 찾기
String uploadURI = "/uploadfile/memberphoto";
String dir = request.getSession().getServletContext().getRealPath(uploadURI);
// 업로드 파일의 물리적 저장
if (!registerRequest.getPhotofile().isEmpty()) {
registerRequest.getPhotofile().transferTo(new File(dir, registerRequest.getEmail()));
registerRequest.setPhoto(registerRequest.getEmail());
}
Member member = memberRegisterService.register(registerRequest);
// 가입 축하 메일 전송
mailHelper.sendMail(member);
redirectAttributes.addFlashAttribute("SUCCESS_MSG", "회원가입 성공");
return "redirect:/member/login";
}
use of org.springframework.validation.ObjectError in project Gemma by PavlidisLab.
the class ArrayDesignFormController method onSubmit.
@Override
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
ArrayDesignValueObject ad = (ArrayDesignValueObject) command;
ArrayDesign existing = arrayDesignService.load(ad.getId());
if (existing == null) {
errors.addError(new ObjectError(command.toString(), null, null, "No such platform with id=" + ad.getId()));
return processFormSubmission(request, response, command, errors);
}
// existing = arrayDesignService.thawLite( existing );
existing.setDescription(ad.getDescription());
existing.setName(ad.getName());
existing.setShortName(ad.getShortName());
String technologyType = ad.getTechnologyType();
if (StringUtils.isNotBlank(technologyType)) {
existing.setTechnologyType(TechnologyType.fromString(technologyType));
}
arrayDesignService.update(existing);
saveMessage(request, "object.updated", new Object[] { ad.getClass().getSimpleName().replaceFirst("Impl", ""), ad.getName() }, "Saved");
// go back to the aray we just edited.
return new ModelAndView(new RedirectView("/arrays/showArrayDesign.html?id=" + ad.getId(), true));
}
use of org.springframework.validation.ObjectError in project molgenis by molgenis.
the class ImportWizardUtil method handleException.
public static void handleException(Exception e, ImportWizard importWizard, BindingResult result, Logger logger, String entityImportOption) {
File file = importWizard.getFile();
if (logger.isWarnEnabled()) {
logger.warn(format("Import of file [%s] failed for action [%s]", Optional.ofNullable(file).map(File::getName).orElse("UNKNOWN"), entityImportOption), e);
}
result.addError(new ObjectError("wizard", "<b>Your import failed:</b><br />" + e.getMessage()));
}
use of org.springframework.validation.ObjectError in project molgenis by molgenis.
the class RestController method handleMethodArgumentNotValidException.
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(BAD_REQUEST)
public ErrorMessageResponse handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
LOG.debug("", e);
List<ErrorMessage> messages = Lists.newArrayList();
for (ObjectError error : e.getBindingResult().getAllErrors()) {
messages.add(new ErrorMessage(error.getDefaultMessage()));
}
return new ErrorMessageResponse(messages);
}
Aggregations