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.training.controller.UserController.java

@PostMapping("/add/input")
public String addUser(@Valid @ModelAttribute("userForm") UserFormValidator userForm,
        BindingResult bindingResult, @ModelAttribute User user, Model model) {

    if (bindingResult.hasErrors()) {
        return ("users/AddUser");
    }//from   w  w  w .  java2s . c  om
    userService.insert(user);
    return ("redirect:/users/view");
}

From source file:fi.nls.fileservice.web.admin.controller.DatasetAdminController.java

@RequestMapping(value = "/tuotteet/{tuote}/versio", method = RequestMethod.POST)
public String saveDatasetVersion(@PathVariable(value = "tuote") String datasetID,
        @Valid DatasetVersion datasetVersion, BindingResult result, Model model) {
    if (result.hasErrors()) {
        Dataset dataset = datasetService.getDatasetById(datasetID);
        model.addAttribute("dataset", dataset);
        model.addAttribute("datasetName", datasetID);
        model.addAttribute("distributionFormats", distributionFormats);
        model.addAttribute("crsDefinitionsJSON", JSONUtils.object2JSON(crsDefinitions));
        return "admin/dataset_version_edit";
    }/*from  ww w.jav a2s . co m*/
    datasetService.saveDatasetVersion(datasetID, datasetVersion);
    return "redirect:/hallinta/tuotteet/{tuote}";
}

From source file:com.branded.holdings.qpc.web.OwnerController.java

@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {/* w w  w  .jav a2  s . co  m*/
        this.clinicService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/" + owner.getId();
    }
}

From source file:com.branded.holdings.qpc.web.OwnerController.java

@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.PUT)
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {//from w  w w.j a v  a  2s  .co m
        this.clinicService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

From source file:com.pet.demo.web.OwnerController.java

@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {/*from   w ww. java 2 s .c  om*/
        this.petDemoService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/" + owner.getId();
    }
}

From source file:com.pet.demo.web.OwnerController.java

@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.PUT)
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {/*from   w  ww .j a  va 2 s . co  m*/
        this.petDemoService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

From source file:com.rambird.miles.web.OwnerController.java

@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {/*from ww  w . ja v a  2 s  .  c  om*/
        this.rambirdService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/" + owner.getId();
    }
}

From source file:com.rambird.miles.web.OwnerController.java

@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.PUT)
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {/*from  w ww  . java  2 s . co  m*/
        this.rambirdService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

From source file:de.iew.web.utils.ValidatingFormAuthenticationFilter.java

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException {
    LoginForm loginForm = new LoginForm();

    /*//from   w w  w .j  a v a  2 s  .c  om
    Validiere zuerst die Logindaten. Da wir hier in einem Filter sind,
    mssen wir die Validierung per Hand vornehmen. Das Validierungsergebnis
    wird dann im Fehlerfall durch eine Exception mitgeteilt.
            
    @see <a href="http://static.springsource.org/spring/docs/3.0.x/reference/validation.html">http://static.springsource.org/spring/docs/3.0.x/reference/validation.html</a>
    */
    DataBinder binder = new DataBinder(loginForm);
    binder.setValidator(this.validator);

    MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(request.getParameterMap());
    binder.bind(mutablePropertyValues);
    binder.validate();

    BindingResult results = binder.getBindingResult();

    if (results.hasErrors()) {
        throw new LoginFormValidationException("validation failed", results);
    }

    return super.attemptAuthentication(request, response);
}

From source file:il.co.brandis.controller.UserController.java

/**
 * Handling user registration - success or failure
*//* w  ww . j av  a 2  s .c o m*/
@RequestMapping(value = "/registration")
public String registerUser(@Valid @ModelAttribute(value = "newUser") User user, BindingResult result,
        ModelMap modelMap) {
    if (result.hasErrors()) {
        logger.warn("Register failed for: " + user.getEmail());
        return "redirect:/user/index";
    } else {
        userService.addUser(user);
        logger.info("Register succeed: " + user.getEmail());
    }
    modelMap.remove("newUser");
    return "redirect:/user/index";
}