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:net.triptech.metahive.web.ConditionOfUseController.java

@RequestMapping(method = RequestMethod.PUT)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String update(@Valid ConditionOfUse conditionOfUse, BindingResult bindingResult, Model uiModel,
        HttpServletRequest request) {/*from  www  .j  av a  2  s.c  o  m*/

    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("conditionOfUse", conditionOfUse);

        FlashScope.appendMessage(getMessage("metahive_object_validation", ConditionOfUse.class), request);

        return "conditions/update";
    }
    uiModel.asMap().clear();
    conditionOfUse.merge();

    FlashScope.appendMessage(getMessage("metahive_edit_complete", ConditionOfUse.class), request);

    return "redirect:/lists";
}

From source file:org.ahp.login.forgot.password.ForgotPasswordController.java

@RequestMapping(method = RequestMethod.POST)
public String registerUser(HttpServletRequest pHttpServletRequest, @ModelAttribute("user") User pUser,
        BindingResult pBindingResult, Model pModel) throws IOException {
    System.out.println(pUser);/*from  w  ww  .  j a va  2s .c  o  m*/
    if (pBindingResult.hasErrors()) {
        return "/login/ForgotPassword.jsp";
    }
    this.mForgotPasswordValidator.validate(pUser, pBindingResult);
    if (pBindingResult.hasErrors()) {
        return "/login/ForgotPassword.jsp";
    }
    User lUserUnderResetPassword = mForgotPasswordService.resetPassword(pUser);
    pHttpServletRequest.getSession().setAttribute(LOGGED_IN_USER, lUserUnderResetPassword);
    return "redirect:/login/Home.jsp";
}

From source file:org.energyos.espi.datacustodian.web.custodian.AssociateUsagePointController.java

@RequestMapping(value = Routes.DATA_CUSTODIAN_RETAIL_CUSTOMER_USAGE_POINTS_CREATE, method = RequestMethod.POST)
public String create(@PathVariable Long retailCustomerId,
        @ModelAttribute("usagePointForm") @Valid UsagePointForm usagePointForm, BindingResult result) {
    if (result.hasErrors())
        return "/custodian/retailcustomers/usagepoints/form";

    Subscription subscription = retailCustomerService.associateByUUID(retailCustomerId,
            UUID.fromString(usagePointForm.getUUID()));

    if (subscription != null) {
        notificationService.notify(subscription, null, null);
    }/*from  w  w  w .j  a v a2  s . c  o m*/
    return "redirect:/custodian/retailcustomers";
}

From source file:cherry.example.web.basic.ex90.BasicEx90ControllerImpl.java

private boolean hasErrors(BasicEx90Form form, BindingResult binding) {

    // ??/*  w  w w .  ja  v a  2  s .c o  m*/
    if (binding.hasErrors()) {
        return true;
    }

    // ?
    if (form.getDt() == null && form.getTm() != null) {
        LogicalErrorUtil.rejectValue(binding, Prop.Dt.getName(), LogicalError.RequiredWhen, Prop.Dt.resolve(),
                Prop.Tm.resolve());
    }

    if (binding.hasErrors()) {
        return true;
    }

    // ??

    if (binding.hasErrors()) {
        return true;
    }

    return false;
}

From source file:com.pkrete.locationservice.admin.controller.mvc.AddUserController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute("userInfo") UserInfo userInfo, BindingResult result) throws Exception {
    validator.validate(userInfo, result);

    if (result.hasErrors()) {
        ModelMap model = new ModelMap();
        this.setReferenceData(request, model);
        return new ModelAndView("add_user", model);
    }/*  w  ww  . j av a2 s  .co m*/

    userInfo.getUser().setCreator(getUser(request).getUsername());
    // Creating UserInfo creates both UserInfo and User
    if (!usersService.create(userInfo)) {
        throw new Exception("Creating user failed.");
    }
    return new ModelAndView("redirect:userowner.htm");
}

From source file:com.work.petclinic.web.OwnerController.java

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

From source file:com.work.petclinic.web.OwnerController.java

@RequestMapping(value = "/{ownerId}/edit", method = RequestMethod.POST)
public String processUpdateOwner(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/ownerForm";
    } else {//from w w  w.  jav a 2s  .  c o m
        this.clinicService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

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

/**
 * Updates the users password and stores it in the database.
 *
 * @param update The new password// www. ja  v a 2s. co m
 * @return Account page
 */
@RequestMapping(value = "/account/password", method = POST)
@PreAuthorize("hasAnyRole('USER','ADMIN')")
public ModelAndView updatePassword(@Valid PasswordChange update, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return new ModelAndView("user/changePassword", "formErrors", result.getAllErrors());
    }

    DukeEncountersUser user = userService.getDukeEncountersUser();
    user.setPassword(userService.hashPassword(update.getNewPassword()));

    DukeEncountersUser storedUser = userService.updateUser(user);

    logger.warn(SecurityMarkers.SECURITY_AUDIT, "User {} changed his password", storedUser.getUsername());

    redirectAttributes.addFlashAttribute("dataUpdated", true);

    return new ModelAndView("redirect:/account");
}

From source file:net.triptech.metahive.web.ConditionOfUseController.java

@RequestMapping(method = RequestMethod.POST)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String create(@Valid ConditionOfUse conditionOfUse, BindingResult bindingResult, Model uiModel,
        HttpServletRequest request) {//from   w  ww  . java 2s  .  c  o  m

    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("conditionOfUse", conditionOfUse);

        FlashScope.appendMessage(getMessage("metahive_object_validation", ConditionOfUse.class), request);

        return "conditions/create";
    }
    uiModel.asMap().clear();
    conditionOfUse.persist();
    conditionOfUse.flush();

    FlashScope.appendMessage(getMessage("metahive_create_complete", ConditionOfUse.class), request);

    return "redirect:/lists";
}

From source file:nl.enovation.addressbook.cqrs.webui.controllers.ContactsController.java

@RequestMapping(value = "{identifier}/delete", method = RequestMethod.POST)
public String formDelete(@ModelAttribute("contact") ContactEntry contact, BindingResult bindingResult) {
    if (!bindingResult.hasErrors()) {
        AggregateIdentifier identifier = new StringAggregateIdentifier(contact.getIdentifier());
        RemoveContactCommand command = new RemoveContactCommand(identifier);

        LOGGER.debug("Dispatching command with name : {}", command.toString());
        commandBus.dispatch(command);/*w  w w  . j a  va 2s .co  m*/

        return "redirect:/contacts";
    }
    return "contacts/delete";
}