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.aplikasi.penjualan.controller.DataBarangHtmlController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String prosesFormEdit(@Valid DataBarang k, BindingResult errors) {
    if (errors.hasErrors()) {
        return "/barang/edit";
    }//from w  w  w  .  j  a  v a2  s . c  o  m
    kd.save(k);
    return "redirect:list";
}

From source file:com.aplikasi.penjualan.controller.DataBarangHtmlController.java

@RequestMapping(value = "/form", method = RequestMethod.POST)
public String prosesForm(@Valid DataBarang k, BindingResult errors) {
    if (errors.hasErrors()) {
        return "/barang/form";
    }//  w ww.j ava  2s .  c o m
    kd.save(k);
    return "redirect:list";
}

From source file:cs544.letmegiveexam.controller.AdminController.java

@RequestMapping(value = "/addSubject", method = RequestMethod.POST)
public String addSubject(@Valid Subject subject, BindingResult result) {
    if (result.hasErrors()) {
        return "addSubject";
    } else {/*from   w  w  w .jav  a  2  s .c  om*/
        subjectService.addSubject(subject);
        return "redirect:/questionSetting";
    }
}

From source file:net.przemkovv.sphinx.web.TaskController.java

@RequestMapping(method = RequestMethod.POST)
public String addTask(@Valid @ModelAttribute("new_task") Task task, BindingResult result) {
    if (result.hasErrors()) {
        return "view.tasks.add";
    }// w  w w .  j ava2 s.  com
    taskService.saveTask(task);
    return "redirect:/tasks";
}

From source file:oauth2.controllers.ChangePasswordController.java

@RequestMapping(method = RequestMethod.POST)
public String submit(HttpServletRequest request, HttpServletResponse response,
        @Validated @ModelAttribute(FORM_ATTRIBUTE_NAME) ChangePasswordForm form, BindingResult result) {

    if (result.hasErrors()) {
        return VIEW_CHANGE_PASSWORD;
    }/*from ww  w  . j  ava  2  s  .c  o m*/
    try {
        changePasswordService.changePassword(form.getUserId(), form.getOldPassword(), form.getNewPassword());
    } catch (ChangePasswordException ex) {
        result.rejectValue("userId", ex.getMessage(), ex.getLocalizedMessage());
    } catch (AuthenticationException ex) {
        result.reject(ex.getMessage(), ex.getLocalizedMessage());
    }
    if (result.hasErrors()) {
        form.clearPasswords();
        return VIEW_CHANGE_PASSWORD;
    }
    return "redirect:" + getTargetUrl(request, response);
}

From source file:technology.tikal.accounts.service.imp.MyAccountImp.java

@Override
@RequestMapping(value = "/personalInfo", method = RequestMethod.POST)
public void updateAccountPersonalInfo(@Valid @RequestBody final PersonalInfo request,
        final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*  www  .  j av a  2s.  c om*/
    String user = SecurityContextHolder.getContext().getAuthentication().getName();
    accountsController.updateAccount(user, request);
}

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

@RequestMapping(value = "/{lineaProductoId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long idCatalogo, @PathVariable final Long lineaProductoId,
        @Valid @RequestBody final LineaDeProductos request, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*w ww  .  j  ava2  s  .  co  m*/
    if (request.getId() != null && Long.compare(request.getId(), lineaProductoId) != 0) {
        throw new MessageSourceResolvableException(new DefaultMessageSourceResolvable(
                new String[] { "NoValidRequest.LineaProductoService.actualizar" },
                new String[] { request.getId() + "" },
                "El id del path no corresponde al de la info mandada en el body"));
    }
    lineaProductoController.actualizar(idCatalogo, lineaProductoId, request);
}

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

@RequestMapping(value = "/update/{userId}", method = RequestMethod.POST)
public String updateUser(@ModelAttribute("user") UserDTO user, @PathVariable("userId") Long id,
        BindingResult result) {

    if (result.hasErrors()) {
        return "/user/userUpdateForm";
    }//from  www  .j  ava 2 s  .c o  m
    userService.updateUser(user);
    return "redirect:/user/allUsers";
}

From source file:gxu.software_engineering.shen10.market.controller.CategoryController.java

@RequestMapping(value = "/categories/add", method = POST)
public String add(Model model, @Valid Category category, BindingResult result) {
    if (result.hasErrors()) {
        List<ObjectError> errors = result.getAllErrors();
        String msg = "??\n";
        for (int i = 0; i < errors.size(); i++) {
            msg += errors.get(i).getDefaultMessage() + "\n";
        }/*from   w  w w . j av a  2  s .c  om*/
        throw new IllegalArgumentException(msg);
    }
    categoryService.add(category);
    model.addAttribute(STATUS, STATUS_OK);
    return BAD_REQUEST;
}

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

@RequestMapping(method = RequestMethod.POST)
public String processForm(@ModelAttribute @Valid CostCenter costCenter, BindingResult result,
        SessionStatus status) {//from   w w w . j a va  2  s  . com
    if (result.hasErrors()) {
        return "costcenter/form";
    }
    inventoryService.save(costCenter);
    status.setComplete();
    return "redirect:/costcenter/list";
}