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.kdubb.socialshowcaseboot.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 . co m*/
    Account account = createAccount(form, formBinding);
    if (account != null) {
        SignInUtils.signin(account.getUsername());
        providerSignInUtils.doPostSignUp(account.getUsername(), request);
        return "redirect:/";
    }
    return null;
}

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

@RequestMapping(value = "/adminEditSetting", method = RequestMethod.POST)
public String adminSetting(@Valid Setting setting, BindingResult result) {
    if (result.hasErrors()) {
        return "adminEditSetting";
    } else {//w  ww. j ava2  s . c om
        long id = 1;
        setting.setId(id);
        settingService.updateSetting(setting);
        return "redirect:/adminPanel";
    }
}

From source file:edu.ijse.tcd.controller.ComplaintController.java

@RequestMapping(value = "addComplaint", method = RequestMethod.POST)
public String addComplaint(@Valid Complaint complaint, BindingResult bindingResult, ModelMap map) {

    if (bindingResult.hasErrors()) {
        ArrayList<Complaint> complaints = complaintService.getComplaints();

        ArrayList<JobCard> jobCards = jobCardService.getJobCards();
        map.addAttribute("jobCards", jobCards);

        map.addAttribute("complaint", complaint);
        map.addAttribute("ComplaintList", complaints);

        return "complaint";
    }//from   w ww. ja  v a2 s . co m
    complaintService.addComplaint(complaint);

    ArrayList<Complaint> complaints = complaintService.getComplaints();
    map.addAttribute("ComplaintList", complaints);

    ArrayList<JobCard> jobCards = jobCardService.getJobCards();
    map.addAttribute("jobCards", jobCards);

    map.addAttribute("complaint", new Complaint());
    return "complaint";

}

From source file:com.controller.ContactoController.java

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

    if (result.hasErrors()) {
        return "index";
    }//from   ww  w.  j  a v a2  s .  co m

    contactoService.addContacto(contacto);

    return "redirect:./showContacts";
}

From source file:com.tsg.dvdlibrarymvc.HomeControllerNoAjax.java

@RequestMapping(value = "/addNewDVDFormNoAjax", method = RequestMethod.POST)
public String addNewDVDNoAjax(@Valid @ModelAttribute("dvd") DVD dvd, BindingResult result) {
    if (result.hasErrors()) {
        return "newDVDFormNoAjax";
    }// ww  w . j a v  a 2  s .c  o m

    //        String dvdTitle = req.getParameter("dvdTitle");
    //        String directorsName = req.getParameter("directorsName");
    //        String mpaaRating = req.getParameter("mpaaRating");
    //        String studio = req.getParameter("studio");
    //        String releaseDate = req.getParameter("releaseDate");
    //
    //        DVD disc1 = new DVD();
    //        disc1.setDvdTitle(dvdTitle);
    //        disc1.setDirectorsName(directorsName);
    //        disc1.setMpaaRating(mpaaRating);
    //        disc1.setStudio(studio);
    //        disc1.setReleaseDate(releaseDate);

    dao.addDVD(dvd);

    return "redirect:displayDVDListNoAjax";

}

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

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

From source file:de.asgarbayli.rashad.hbd.controllers.ParametersController.java

@RequestMapping(value = Navigation.PARAMETERS, method = RequestMethod.GET)
public ModelAndView showParameters(@ModelAttribute(Navigation.PARAMETERS) Parameters parameters,
        BindingResult result, Model model) {
    // Check for binding errors
    if (result.hasErrors()) {
        String message = "Binding result on " + Navigation.PARAMETERS
                + " has error(s) for the GET request method.";
        Messages.showErrorMessage(model, message);
        return new ModelAndView(Navigation.PARAMETERS);
    }// w  w w  .  j  a  v  a 2 s. c o  m

    parameters.loadParameters();
    return new ModelAndView(Navigation.PARAMETERS, "command", parameters);
}

From source file:org.busko.routemanager.web.api.RouteSubmissionApiController.java

@RequestMapping(method = RequestMethod.POST)
public String create(@Valid RouteSubmission routeSubmission, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        return "dataAccessFailure";
    }/*from ww w  .  j a va 2s.c o  m*/
    uiModel.asMap().clear();

    routeSubmission.setSubmittedDateTime(new Date());
    routeSubmission.uploadFileData();
    routeSubmission.persist();
    return "ok";
}

From source file:technology.tikal.ventas.service.pedimento.PedimentoService.java

@RequestMapping(value = "/{pedimentoId}", method = RequestMethod.POST)
public void actualizar(@PathVariable final Long pedidoId, @PathVariable final Long pedimentoId,
        @Valid @RequestBody final Pedimento request, final BindingResult result) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*  w  ww  .j a  v  a2 s. com*/
    if (Long.compare(request.getId(), pedimentoId) != 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"));
    }
    pedimentoController.actualizar(pedidoId, pedimentoId, request);
}

From source file:app.web.AbstractCrudController.java

@RequestMapping(value = { "/create", "/edit" }, method = RequestMethod.POST)
public String sendForm(@Valid final T form, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        Class<T> clazz = getTypeClass();
        return clazz.getSimpleName().toLowerCase() + "/form"; // stay on the same view so we can display the validation errors
    }/*from  w w w.ja va 2s .c  o m*/
    if (form.isPersistent()) {
        new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                form.update();
            }
        });
    } else {
        form.save(); // no need for a transaction?
    }
    // FIXME: find out why the item must be called "form"
    return "redirect:.";
}