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.swcguild.addressbookmvc.controller.HomeControllerNoAjax.java

@RequestMapping(value = "/editContactNoAjax", method = RequestMethod.POST)
public String editContactNoAjax(@Valid @ModelAttribute("contact") Contact contact, BindingResult result) {
    if (result.hasErrors()) {
        return "editContactFormNoAjax";
    }/*from   www  . j  a  va2s.c o  m*/

    dao.updateContact(contact);

    return "redirect:displayAddressBookNoAjax";
}

From source file:controller.Crud.java

@RequestMapping(value = "/edit/{id}", method = RequestMethod.POST)
public ModelAndView update(@Valid @ModelAttribute("hallo") Hallo hallo, BindingResult result,
        @PathVariable("id") String id) {
    if (result.hasErrors()) {
        ModelAndView modelAndView = new ModelAndView("crud/edit");
        modelAndView.addObject("command", hallo);
        modelAndView.addObject("id", id);
        modelAndView.addObject("error", result.getAllErrors());
        return modelAndView;
    } else {//ww  w.  ja v  a  2s .  c  om
        config.simpanUpdate(hallo);
        return new ModelAndView("redirect:/show");
    }
}

From source file:cz.muni.fi.mir.controllers.RevisionController.java

@Secured("ROLE_ADMINISTRATOR")
@RequestMapping(value = { "/create/", "/create" }, method = RequestMethod.POST)
@SiteTitle("{navigation.revision.create}")
public ModelAndView createRevisionSubmit(@Valid @ModelAttribute("revisionForm") RevisionForm revisionForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("revisionForm", revisionForm);
        mm.addAttribute(model);//w  w  w  . j  a  v a  2 s.  c o m

        return new ModelAndView("revision_create", mm);
    } else {
        revisionService.createRevision(mapper.map(revisionForm, Revision.class));

        return new ModelAndView("redirect:/revision/list/");
    }
}

From source file:cz.muni.fi.mir.controllers.RevisionController.java

@Secured("ROLE_ADMINISTRATOR")
@RequestMapping(value = { "/edit/", "/edit/" }, method = RequestMethod.POST)
@SiteTitle("{entity.revision.edit}")
public ModelAndView editRevisionSubmit(@Valid @ModelAttribute("revisionForm") RevisionForm revisionForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("revisionForm", revisionForm);
        mm.addAttribute(model);/*w w  w .  j av a  2 s .  co  m*/

        return new ModelAndView("revision_edit", mm);
    } else {
        revisionService.updateRevision(mapper.map(revisionForm, Revision.class));

        return new ModelAndView("redirect:/revision/list/");
    }
}

From source file:io.hedwig.petclinic.ui.web.PetController.java

@RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Pet pet, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        System.out.println("PET in if");
        System.out.println("PET " + result.toString());
        return "pets/petForm";
    } else {//from   ww w  . ja  v  a 2 s.c om
        System.out.println("PET in else");
        this.clinicService.savePet(pet);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

From source file:com.example.securelogin.app.unlock.UnlockController.java

@RequestMapping(method = RequestMethod.POST)
public String unlock(@Validated UnlockForm form, BindingResult bindingResult, Model model,
        RedirectAttributes attributes) {
    if (bindingResult.hasErrors()) {
        return showForm(form);
    }//ww  w  . j  av  a2  s  .c o m

    try {
        unlockService.unlock(form.getUsername());
        attributes.addFlashAttribute("username", form.getUsername());
        return "redirect:/unlock?complete";
    } catch (BusinessException e) {
        model.addAttribute(e.getResultMessages());
        return showForm(form);
    }
}

From source file:com.github.dbourdette.otto.web.controller.admin.MailController.java

@RequestMapping(value = "/mail/send", method = RequestMethod.POST)
public String send(@ModelAttribute("form") @Valid Mail form, BindingResult result, Model model) {
    if (result.hasErrors()) {
        model.addAttribute("navItem", "mail");

        return "admin/mail_send_form";
    }/*from   w ww  . j ava  2 s.  c o  m*/

    try {
        mailer.send(form);

        flashScope.message("Mail has been sent to " + form.getTo());
    } catch (Exception e) {
        model.addAttribute("stacktrace", ExceptionUtils.getFullStackTrace(e));

        return "error";
    }

    return "redirect:/mail/send";
}

From source file:id.go.kemdikbud.tandajasa.controller.PegawaiController.java

@RequestMapping(value = "/pegawai/form", method = RequestMethod.POST)
public String prosesForm(@ModelAttribute @Valid Pegawai pegawai, BindingResult errors, SessionStatus status) {
    if (errors.hasErrors()) {
        return "/pegawai/form";
    }//from   w  ww.  j av a  2  s .c  om

    pegawaiDao.save(pegawai);
    status.setComplete();
    return "redirect:list";
}

From source file:lcn.samples.petclinic.controller.PetController.java

@RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.POST)
public String processCreationForm(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
    new PetValidator().validate(pet, result);
    if (result.hasErrors()) {
        return "pets/createOrUpdatePetForm";
    } else {/*from ww  w  .ja  va2  s.  co  m*/
        this.clinicService.savePet(pet);
        status.setComplete();
        return "redirect:/owners/{ownerId}.do";
    }
}

From source file:org.openmrs.module.patientflags.web.FindFlaggedPatientsEmailController.java

/**
 *  Handle the request to create an flag email
 *///from ww  w. j a  v a  2  s .  c om

@RequestMapping(method = RequestMethod.GET)
public ModelAndView processRequest(@ModelAttribute("flag") Flag flag, BindingResult result,
        SessionStatus status) {

    if (result.hasErrors()) {
        throw new APIException("Invalid parameter passed to FindFlaggedPatientsEmailController");
    }

    // get all Patients that trigger the selected Flag
    FlagService flagService = Context.getService(FlagService.class);
    flag = flagService.getFlag(flag.getFlagId());
    Cohort flaggedPatients = flagService.getFlaggedPatients(flag);
    Cohort allPatients = Context.getPatientSetService().getAllPatients();

    // create the model map
    ModelMap model = new ModelMap();
    model.addAttribute("flag", flag);
    model.addAttribute("allPatients", allPatients);
    if (flaggedPatients != null) {
        model.addAttribute("flaggedPatients", flaggedPatients.getMemberIds());
    } else {
        model.addAttribute("flaggedPatients", null);
    }

    // clears the command object from the session
    status.setComplete();

    // displays the query results
    return new ModelAndView("/module/patientflags/findFlaggedPatientsEmailResults", model);
}