Search in sources :

Example 71 with ObjectError

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";
}
Also used : ServletException(javax.servlet.ServletException) User(org.springframework.security.core.userdetails.User) LoginUser(com.dappermoose.stsimplefinance.data.LoginUser) ObjectError(org.springframework.validation.ObjectError) LoginUser(com.dappermoose.stsimplefinance.data.LoginUser) Transactional(javax.transaction.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 72 with ObjectError

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";
}
Also used : ObjectError(org.springframework.validation.ObjectError) File(java.io.File) Member(com.bitcamp.mvc.model.Member) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 73 with ObjectError

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));
}
Also used : ObjectError(org.springframework.validation.ObjectError) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 74 with ObjectError

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()));
}
Also used : ObjectError(org.springframework.validation.ObjectError) File(java.io.File)

Example 75 with ObjectError

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);
}
Also used : ObjectError(org.springframework.validation.ObjectError) ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse)

Aggregations

ObjectError (org.springframework.validation.ObjectError)106 FieldError (org.springframework.validation.FieldError)19 BindingResult (org.springframework.validation.BindingResult)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 BindException (org.springframework.validation.BindException)14 ArrayList (java.util.ArrayList)13 MapBindingResult (org.springframework.validation.MapBindingResult)13 Test (org.junit.jupiter.api.Test)12 ModelAndView (org.springframework.web.servlet.ModelAndView)10 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 Test (org.junit.Test)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 Errors (org.springframework.validation.Errors)6 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5