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:technology.tikal.ventas.service.pedido.PedidoRaizService.java

@RequestMapping(value = "/{pedidoId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long pedidoId, @Valid @RequestBody final PedidoRaiz request,
        final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*  w w  w.  jav a 2s.c  o  m*/
    if (Long.compare(request.getId(), pedidoId) != 0) {
        throw new MessageSourceResolvableException(new DefaultMessageSourceResolvable(
                new String[] { "NoValidRequest.PedidoService.actualizarPedido" },
                new String[] { request.getId() + "" },
                "El id del path no corresponde al de la info mandada en el body"));
    }
    pedidoRaizController.actualizar(request);
}

From source file:com.mir00r.controller.HelloController.java

@RequestMapping(value = "/addemp", method = RequestMethod.POST)
public String addEmployee(ModelMap map, @Valid @ModelAttribute("employee") Employee employee,
        BindingResult result) {

    if (result.hasErrors()) {
        return "addemployee";
    }//  w  ww. ja va2 s . c  o  m

    // No need to declear this section
    //        Employee employee = new Employee();
    //        employee.setEname(ename);
    //        employee.setEaddress(eaddress);
    //        map.addAttribute("employee", employee);
    return "einfo";
}

From source file:com.solxiom.social.signup.SignupController.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String signup(@Valid SignupForm form, BindingResult formBinding, WebRequest request) {
    if (formBinding.hasErrors()) {
        return null;
    }/*w  w w. j  av a 2s  .  c  o m*/
    Account account = createAccount(form, formBinding);
    if (account != null) {
        SignInUtils.signin(account.getUsername());
        ProviderSignInUtils.handlePostSignUp(account.getUsername(), request);
        return "redirect:/";
    }
    return null;
}

From source file:de.dominikschadow.duke.encounters.controller.SearchController.java

/**
 * Search the encounters based on the given search filter.
 *
 * @param searchFilter The search filter identifying encounters
 * @param result       BindingResult/*from   ww  w  .  ja v  a 2  s . c  om*/
 * @return ModelAndView with encounters URL and a model map
 */
@RequestMapping(value = "/encounters", method = POST)
public ModelAndView searchEncounters(@Valid SearchFilter searchFilter, BindingResult result) {
    if (result.hasErrors()) {
        return new ModelAndView("search", "formErrors", result.getAllErrors());
    }

    List<Encounter> encounters = encounterService.getEncounters(searchFilter);

    Map<String, Object> modelMap = new LinkedHashMap<>();
    modelMap.put("encounters", encounters);
    modelMap.put("searchFilter", searchFilter);

    return new ModelAndView("encounters", modelMap);
}

From source file:gallery.web.validator.user.UserCmsValidator.java

public BindingResult bindAndValidate(User command, HttpServletRequest request, User old_command) {
    BindingResult err = bindAndValidate(command, request);
    if (!err.hasErrors()) {
        if ((command.getPassword() == null && command.getPassword_repeat() != null)
                || (command.getPassword() != null
                        && !command.getPassword().equals(command.getPassword_repeat()))) {
            err.rejectValue("password_repeat", "password_repeat.different");
        }/*from ww w.  jav  a  2 s . c  o m*/
        if (old_command == null) {
            if (userService.getRowCount("login", command.getLogin()) > 0) {
                err.rejectValue("login", "exists.login");
            }
            if (userService.getRowCount("email", command.getEmail()) > 0) {
                err.rejectValue("email", "exists.email");
            }
        } else {
            if (command.getPassword() == null || command.getPassword().equals("")) {
                command.setPassword(old_command.getPassword());
            }
            if ((!command.getLogin().equals(old_command.getLogin()))
                    && (userService.getRowCount("login", command.getLogin()) > 0)) {
                err.rejectValue("login", "exists.login");
            }
            if ((!command.getEmail().equals(old_command.getEmail()))
                    && (userService.getRowCount("email", command.getEmail()) > 0)) {
                err.rejectValue("email", "exists.email");
            }
            command.setNewRoles(old_command.getRoles());
        }
    }
    return err;
}

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

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

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

@RequestMapping(value = "/{productoId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long idCatalogo, @PathVariable final Long productoId,
        @Valid @RequestBody final Producto request, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }//  w w  w  . j av  a 2s .com
    if (request.getId() != null && Long.compare(request.getId(), productoId) != 0) {
        throw new MessageSourceResolvableException(
                new DefaultMessageSourceResolvable(new String[] { "NoValidRequest.ProductoService.actualizar" },
                        new String[] { request.getId() + "" },
                        "El id del path no corresponde al de la info mandada en el body"));
    }
    productoController.actualizar(idCatalogo, productoId, request);
}

From source file:technology.tikal.ventas.service.envio.EnvioService.java

@RequestMapping(value = "/{envioId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long pedidoId, @PathVariable final Long envioId,
        @Valid @RequestBody final Envio request, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }//w w  w . j av  a2  s .  c  o m
    if (Long.compare(request.getId(), envioId) != 0) {
        throw new MessageSourceResolvableException(new DefaultMessageSourceResolvable(
                new String[] { "NoValidRequest.PedimentoService.actualizar" },
                new String[] { request.getId() + "" },
                "El id del path no corresponde al de la info mandada en el body"));
    }
    envioController.actualizar(pedidoId, envioId, request);
}

From source file:technology.tikal.ventas.service.pedido.PartidaService.java

@RequestMapping(value = "/{partidaId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long pedidoId, @PathVariable final Long partidaId,
        @Valid @RequestBody final Partida request, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*from  w w  w  .ja  va2s .  c  o m*/
    if (Long.compare(request.getId(), partidaId) != 0) {
        throw new MessageSourceResolvableException(new DefaultMessageSourceResolvable(
                new String[] { "NoValidRequest.PartidaService.actualizarPedido" },
                new String[] { request.getId() + "" },
                "El id del path no corresponde al de la info mandada en el body"));
    }
    partidaController.actualizar(pedidoId, partidaId, request);
}

From source file:technology.tikal.ventas.service.pedido.SubPedidoService.java

@RequestMapping(value = "/{subPedidoId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long pedidoId, @PathVariable final Long subPedidoId,
        @Valid @RequestBody final SubPedido request, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }//from w w w.j a v a 2s .c om
    if (Long.compare(request.getId(), subPedidoId) != 0) {
        throw new MessageSourceResolvableException(new DefaultMessageSourceResolvable(
                new String[] { "NoValidRequest.SubPedidoService.actualizarPedido" },
                new String[] { request.getId() + "" },
                "El id del path no corresponde al de la info mandada en el body"));
    }
    subPedidoController.actualizar(pedidoId, request);
}