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.pet.demo.web.VisitController.java

@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
public String processNewVisitForm(@Valid Visit visit, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "pets/createOrUpdateVisitForm";
    } else {//from w  w  w  .  java 2s . c om
        this.petdemoService.saveVisit(visit);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

From source file:io.hedwig.petclinic.ui.web.MessageController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) {
    if (result.hasErrors()) {
        return new ModelAndView("messages/form", "formErrors", result.getAllErrors());
    }//from   www.j av a2 s .  c  om
    message = this.messageRepository.save(message);
    redirect.addFlashAttribute("statusMessage", "Successfully created a new message");
    return new ModelAndView("redirect:/inbox/{message.id}", "message.id", message.getId());
}

From source file:com.trenako.web.controllers.AuthController.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String createUser(@Valid @ModelAttribute Account account, BindingResult result, ModelMap model) {

    if (result.hasErrors()) {
        model.addAttribute(account);// w  w  w . jav  a 2 s  .co m
        return "auth/signup";
    }

    try {
        Account newUser = signupService.createAccount(account);

        // automatically sign in the new user
        signupService.authenticate(newUser);

        return "redirect:/default";
    } catch (DuplicateKeyException ex) {
        model.addAttribute(account);
        EMAIL_ADDRESS_OR_DISPLAY_NAME_ALREADY_TAKEN.appendToModel(model);
        return "auth/signup";
    }
}

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

@RequestMapping(value = MainURIResource.PATH_SYS_PRIVILEGE_ADD, method = { RequestMethod.POST })
@ResponseBody//from w ww .j av a2s.  c  o  m
public PrivilegeDto add(
        @Validated @ModelAttribute(MainURIResource.MODEL_PRIVILEGE_DTO) PrivilegeDto privilegeDto,
        BindingResult result) throws ValidateException, BusinessException {
    if (result.hasErrors()) {
        throw new ValidateException(result.getFieldError().getObjectName(), result.getFieldError().getField(),
                result.getFieldError().getDefaultMessage());
    }
    return privilegeService.savePrivilege(privilegeDto);
}

From source file:cz.PA165.vozovyPark.controller.ServiceIntervalController.java

@RequestMapping(value = "/serviceInterval/update/{serviceIntervalId}", method = RequestMethod.POST)
public String updateServiceInterval(@ModelAttribute("serviceInterval") ServiceIntervalDTO serviceInterval,
        @PathVariable("serviceIntervalId") Long id, BindingResult result) {

    if (result.hasErrors()) {
        return "/serviceInterval/serviceIntervalUpdateForm";
    }// www  .j a v  a2  s  .  co m
    serviceIntervalService.updateSI(serviceInterval);
    return "redirect:/serviceInterval/all";
}

From source file:ru.trett.cis.controllers.DeviceBrandController.java

@RequestMapping(method = RequestMethod.POST)
public String processForm(@ModelAttribute @Valid DeviceBrand deviceBrand, BindingResult result,
        SessionStatus status) {// ww w . j a  v a 2s .com
    if (result.hasErrors())
        return "devicebrand/form";
    inventoryService.update(deviceBrand);
    status.setComplete();
    return "redirect:/devicebrand/list";
}

From source file:ru.trett.cis.controllers.DeviceTypeController.java

@RequestMapping(method = RequestMethod.POST)
public String processForm(@ModelAttribute @Valid DeviceType deviceType, BindingResult result,
        SessionStatus status) {/*  w ww  . ja va 2 s.  c  o m*/
    if (result.hasErrors())
        return "devicetype/form";
    inventoryService.update(deviceType);
    status.setComplete();
    return "redirect:/devicetype/list";
}

From source file:ru.trett.cis.controllers.HomeController.java

@RequestMapping(value = "/profile", method = RequestMethod.POST)
public String save(@Valid @ModelAttribute User user, BindingResult result, SessionStatus session) {
    if (result.hasErrors())
        return "home/profile";
    inventoryService.save(user);//w  w w. j  av  a  2 s  .c  om
    session.setComplete();
    return "redirect:/home/profile";
}

From source file:org.energyos.espi.datacustodian.web.custodian.RetailCustomerController.java

@RequestMapping(value = Routes.DATA_CUSTODIAN_RETAIL_CUSTOMER_CREATE, method = RequestMethod.POST)
public String create(@ModelAttribute("retailCustomer") @Valid RetailCustomer retailCustomer,
        BindingResult result) {
    if (result.hasErrors()) {
        return "retailcustomers/form";
    } else {/*from w  ww. j  a  v a 2s  . com*/
        try {
            service.persist(retailCustomer);
            return "redirect:/custodian/retailcustomers";
        } catch (Exception e) {
            return "retailcustomers/form";
        }
    }
}

From source file:ru.codemine.ccms.router.ActionEventsRouter.java

@RequestMapping(value = "/actions/create", method = RequestMethod.POST)
public String newAction(@Valid @ModelAttribute(value = "newActionFrm") ActionEvent actionEvent,
        BindingResult result, ModelMap model) {
    if (result.hasErrors()) {
        model.addAllAttributes(utils.prepareModel());
        model.addAttribute("allShops", shopService.getAllOpen());

        return "pages/actions/newaction";
    }// ww  w .jav a 2 s .  com

    actionEvent.setCreator(employeeService.getCurrentUser());

    actionEventService.create(actionEvent);

    return "redirect://actions/currentFuture";
}