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:pl.altkom.spring.capgemini.web.controller.CustomerController.java

@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveCustomer(@Valid Customer customer, BindingResult result) {

    logger.debug(customer);//from w ww.ja  v  a2s  .  co  m

    if (result.hasErrors()) {
        logger.warn("bd walidacji");
        return "customer/edit-customer";
    }

    return "redirect:/home";
}

From source file:agendaspring.web.controladores.ContactoController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addContact(@ModelAttribute("contacto") Contacto contacto, BindingResult result) {

    if (result.hasErrors()) {
        return "index";
    }/*from   w  ww.  j  a  v a  2s  .c  om*/

    contactoService.addContacto(contacto);

    return "redirect:./index";
}

From source file:controller.Crud.java

@RequestMapping(value = "/tambahdata", method = RequestMethod.POST)
public ModelAndView simpan(@Valid @ModelAttribute("hallo") Hallo hallo, BindingResult result) {
    if (result.hasErrors()) {
        ModelAndView modelAndView = new ModelAndView("crud/tambah");
        modelAndView.addObject("command", new Hallo());
        modelAndView.addObject("error", result.getAllErrors());
        return modelAndView;
    } else {/*from  w  ww . j  a  v a  2s .co m*/
        config.tambahData(hallo);
        return new ModelAndView("redirect:show");
    }
}

From source file:com.mycompany.doctorapp.controller.SicknessController.java

@RequestMapping(value = "/sickness", method = RequestMethod.POST)

//post a new sickness as a patient
public String newSickness(@Valid @ModelAttribute("sicknes") Sickness sickness, BindingResult bindingresult) {
    if (bindingresult.hasErrors()) {
        return "redirect:/index";
    }// w  ww  .jav a  2  s  .c  om
    patientService.addSickness(sickness);
    return "redirect:/index";
}

From source file:org.openmrs.module.crossdistro.web.controller.CrossdistroController.java

/**
 * All the parameters are optional based on the necessity
 * //from   w ww  .  ja  v a 2s  .c  om
 * @param httpSession
 * @param anyRequestObject
 * @param errors
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public String onPost(HttpSession httpSession, @ModelAttribute("anyRequestObject") Object anyRequestObject,
        BindingResult errors) {

    if (errors.hasErrors()) {
        // return error view
    }

    return VIEW;
}

From source file:com.iselect.web.controller.PageFlowController.java

@RequestMapping(value = { "/edit{id}" }, method = RequestMethod.POST)
public String editPageFlow(@Valid @ModelAttribute(MODEL_PAGE_REQEST) PageRequestDto pageRequest,
        BindingResult results) {
    if (results.hasErrors())
        return "pageflow.edit";
    pageFlowService.updatePageResponses(pageRequest);
    return "redirect:./list";
}

From source file:com.jjcosare.calculator.controller.CalculatorController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
public @ResponseBody Object getCalculation(@Valid CalculatorForm calculatorForm, BindingResult bindingResult) {

    Object result = null;//  w ww  .  j  av a  2 s  .  c  o m
    if (bindingResult.hasErrors()) {
        Map<String, String> errorMap = new HashMap<>();
        for (FieldError error : bindingResult.getFieldErrors()) {
            errorMap.put(error.getField(), error.getDefaultMessage());
        }
        result = errorMap;
    } else {
        result = calculatorService.getCalculation(calculatorForm);
    }
    return result;
}

From source file:io.curly.gathering.item.ItemController.java

/**
 * Method that handle user's intent to add a new item to a list
 * @param body valid body for request//w  ww .  j  a  va  2s. c  o  m
 * @param listId list to be added to
 * @param user current user on context
 * @param bindingResult result of validation of body
 * @return 400 if result returns errors or 201 if ok
 */
@RequestMapping(value = "/add/artifact", method = { RequestMethod.PUT, RequestMethod.POST })
public Callable<HttpEntity<?>> addItem(@Valid @RequestBody AddableItemBody body, @PathVariable String listId,
        @GitHubAuthentication User user, BindingResult bindingResult) {

    if (bindingResult.hasErrors()) {
        return () -> new ResponseEntity<Object>(new ModelErrors(bindingResult), HttpStatus.BAD_REQUEST);
    } else {
        return () -> {
            this.interaction.addItem(new AddableItem(body.getItem(), listId, ItemType.ARTIFACT), user);
            return new ResponseEntity<>(HttpStatus.CREATED);
        };
    }
}

From source file:com.stephengream.simplecms.web.controllers.ProfileController.java

@RequestMapping(value = "new", method = RequestMethod.POST)
public String postNewUser(@ModelAttribute("user") @Valid UserCreationForm form, BindingResult result) {
    if (!result.hasErrors()) {
        if (userService.hasUser(form.getUsername())) {
            result.rejectValue("username", "newuser.error.usernameInUse");
            return NEW_PROFILE;
        }//from w ww.  ja  v a2 s .  c  o  m
        userService.createUser(form.getUsername(), form.getPassword(), form.getEmail());
        return NEW_USER_OK;
    }
    return NEW_PROFILE;
}

From source file:com.pw.ism.controllers.CommunicationController.java

@RequestMapping(value = "/newmessage", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<String> newReport(@Valid @RequestBody AsiNetworkReport report,
        BindingResult bindingResults) {

    if (bindingResults.hasErrors()) {
        LOGGER.info("JSON not correct, BADREQUEST! Count: {}", bindingResults.getFieldErrorCount());
        return new ResponseEntity<>("NOK!", HttpStatus.BAD_REQUEST);
    } else {/*from   www.ja v a 2 s . c  om*/
        LOGGER.info("new post for message, customer: {}, network: {}, text: {}, sensor: {}", new Object[] {
                report.getCustomer(), report.getNetwork(), report.getText(), report.getSensor() });
        Message message = new Message(report.getCustomer(), report.getNetwork(),
                "Sensor ID: " + report.getSensor() + " Message: " + report.getText());
        messageRepository.save(message);
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }

}