Example usage for org.springframework.validation BindingResult hasErrors

List of usage examples for org.springframework.validation BindingResult hasErrors

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult hasErrors.

Prototype

boolean hasErrors();

Source Link

Document

Return if there were any errors.

Usage

From source file:com.wiiyaya.consumer.web.main.controller.UserController.java

@RequestMapping(value = MainURIResource.PATH_SYS_USER_AMD, method = { RequestMethod.PUT })
@ResponseBody/*from w  ww . ja v a 2  s  .c  o  m*/
public void amend(
        @Validated @ModelAttribute(MainURIResource.MODEL_BACKEND_USER_DTO) BackendUserDto backendUserDto,
        BindingResult result) throws ValidateException, BusinessException {
    if (result.hasErrors()) {
        throw new ValidateException(result.getFieldError().getObjectName(), result.getFieldError().getField(),
                result.getFieldError().getDefaultMessage());
    }
    backendUserService.updateUser(backendUserDto);
}

From source file:nl.enovation.addressbook.cqrs.webui.controllers.ContactsController.java

@RequestMapping(value = "{identifier}/edit", method = RequestMethod.POST)
public String formEditSubmit(@ModelAttribute("contact") @Valid ContactEntry contact,
        BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return "contacts/edit";
    }/*from w  w  w . j  a  va 2s .c  o  m*/

    AggregateIdentifier identifier = new StringAggregateIdentifier(contact.getIdentifier());
    AbstractContactCrudCommand command = new UpdateContactCommand(identifier, contact);

    LOGGER.debug("Dispatching command with name : {}", command.toString());
    commandBus.dispatch(command);

    return "redirect:/contacts/" + contact.getIdentifier();
}

From source file:org.duracloud.account.app.controller.DuracloudMillController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST)
@Transactional/*from   w  ww .ja  v a  2s.  c o m*/
public ModelAndView update(@ModelAttribute("duracloudMill") @Valid DuracloudMillForm form,
        BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
    boolean hasErrors = bindingResult.hasErrors();
    if (hasErrors) {
        return new ModelAndView(BASE_MAPPING + "/edit");
    }

    this.duracloudMillConfigService.set(form.getDbHost(), form.getDbPort(), form.getDbName(),
            form.getDbUsername(), form.getDbPassword(), form.getAuditQueue(), form.getAuditLogSpaceId());
    UserFeedbackUtil.addSuccessFlash("Successfully updated!", redirectAttributes);
    return new ModelAndView(new RedirectView(BASE_MAPPING, true));
}

From source file:org.duracloud.account.app.controller.GlobalPropertiesController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST)
@Transactional//from   ww  w . j av  a2s  .c  om
public ModelAndView update(@ModelAttribute(GLOBAL_PROPERTIES_ATTRIBUTE) @Valid GlobalPropertiesForm form,
        BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
    boolean hasErrors = bindingResult.hasErrors();
    if (hasErrors) {
        return new ModelAndView(BASE_MAPPING + "/edit");
    }

    this.globalPropertiesConfigService.set(form.getInstanceNotificationTopicArn(),
            form.getCloudFrontAccountId(), form.getCloudFrontKeyId(), form.getCloudFrontKeyPath());

    UserFeedbackUtil.addSuccessFlash("Successfully updated!", redirectAttributes);
    return new ModelAndView(new RedirectView(BASE_MAPPING, true));
}

From source file:controllers.ProducerCompanyController.java

@RequestMapping(value = "/register", method = RequestMethod.POST, params = "save")
public ModelAndView save(@ModelAttribute("producerForm") @Valid ProducerCompanyForm form,
        BindingResult binding) {
    ModelAndView result;//from   www.  jav a  2 s.  c o m
    ProducerCompany producer;

    if (binding.hasErrors()) {
        result = createEditModelAndView(form);
    } else {
        try {
            producer = producerService.reconstruct(form);
            producerService.save(producer);
            result = new ModelAndView("redirect:../security/login.do");
        } catch (IllegalArgumentException oops) {
            String msg;
            if (oops.getMessage() != null && oops.getMessage().startsWith("actor")) {
                msg = oops.getMessage();
            } else {
                msg = "actor.error.commit";
            }
            result = createEditModelAndView(form, msg);
        } catch (Throwable oops) {
            result = createEditModelAndView(form, "actor.error.commit");
        }
    }
    return result;
}

From source file:org.halkneistiyor.social.web.SignupController.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String signup(@Valid SignupForm form, BindingResult formBinding, WebRequest request) {
    System.out.println(formBinding);
    if (formBinding.hasErrors()) {
        return null;
    }/*from   ww w. j  a v a2  s  . c  om*/
    SocialUser su = createUser(form, formBinding);
    System.out.println(su);
    if (su != null) {
        System.out.println("signin...");
        SignInUtils.signin(su.getUserId());
        System.out.println("postSignup...");
        ProviderSignInUtils.handlePostSignUp(su.getUserId(), request);
        System.out.println("redirect...");
        return "redirect:/";
    }
    return null;
}

From source file:technology.tikal.ventas.service.catalogo.LineaProductoService.java

@RequestMapping(produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
public Page<LineaDeProductos[]> consultar(@PathVariable final Long idCatalogo,
        @Valid @ModelAttribute final PaginationDataLong pagination, final BindingResult resultPagination,
        final HttpServletRequest httpRequest) {
    if (resultPagination.hasErrors()) {
        throw new NotValidException(resultPagination);
    }/*from   ww  w.  j  a v a2 s  .  c  o m*/
    Page<LineaDeProductos[]> r = PaginationModelFactory.getPage(
            lineaProductoController.consultar(idCatalogo, pagination), "Pedido", httpRequest.getRequestURI(),
            null, pagination);
    return r;
}

From source file:cherry.sqlman.tool.search.SqlSearchControllerImpl.java

private boolean hasErrors(SqlSearchForm form, BindingResult binding) {

    // ??//from   www . j a  va 2 s .c  o  m
    if (binding.hasErrors()) {
        return true;
    }

    // ?

    // ??

    return false;
}

From source file:com.dub.skoolie.web.controller.system.schedule.SystemGradingPeriodController.java

@RequestMapping(value = "/system/schedule/gradingperiod", method = RequestMethod.POST)
public ModelAndView addGradingPeriod(@Valid GradingPeriodBean gradingPeriodBean, BindingResult result,
        Model model, HttpServletRequest request) {
    String referrer = request.getHeader("Referer");
    if (result.hasErrors()) {
        if (!referrer.equals("/system/schedule/gradingperiod")) {
            return new ModelAndView("redirect:" + referrer);
        }//  w  w w .  j  av  a  2  s  .com
        model.addAttribute("gradingPeriodBeans", uiGradingPeriodServiceImpl.getGradingPeriods());
        model.addAttribute("gradingPeriodBean", gradingPeriodBean);
        model.addAttribute("schoolYears", uiGradingPeriodServiceImpl.getSchoolYears());
        return new ModelAndView("system/schedule/gradingperiod");
    }
    uiGradingPeriodServiceImpl.addGradingPeriod(gradingPeriodBean);
    return new ModelAndView("redirect:" + referrer);
}

From source file:com.dub.skoolie.web.controller.system.schedule.SystemSchoolYearController.java

@RequestMapping(value = "/system/schedule/schoolyear", method = RequestMethod.POST)
public ModelAndView editSchoolYear(@Valid SchoolYearBean schoolYearBean, BindingResult result, Model model,
        HttpServletRequest request) {//  ww w .  ja  v a2  s  .  c  o  m
    String referrer = request.getHeader("Referer");
    if (result.hasErrors()) {
        if (!referrer.equals("/system/schedule/schoolyear")) {
            return new ModelAndView("redirect:" + referrer);
        }
        model.addAttribute("schoolYearBeans", uiSchoolYearServiceImpl.getSchoolYears());
        model.addAttribute("schoolYearBean", schoolYearBean);
        model.addAttribute("allSchools", uiSchoolYearServiceImpl.getAllSchools());
        return new ModelAndView("system/schedule/schoolyear");
    }
    uiSchoolYearServiceImpl.addSchoolYear(schoolYearBean);
    return new ModelAndView("redirect:" + referrer);
}