Example usage for org.springframework.validation BindingResult reject

List of usage examples for org.springframework.validation BindingResult reject

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult reject.

Prototype

void reject(String errorCode, String defaultMessage);

Source Link

Document

Register a global error for the entire target object, using the given error description.

Usage

From source file:co.propack.controller.checkout.NullGiftCardController.java

@RequestMapping(value = "/apply", method = RequestMethod.POST)
public String applyGiftCard(HttpServletRequest request, HttpServletResponse response, Model model,
        @ModelAttribute("orderInfoForm") OrderInfoForm orderInfoForm,
        @ModelAttribute("shippingInfoForm") ShippingInfoForm shippingForm,
        @ModelAttribute("billingInfoForm") BillingInfoForm billingForm,
        @ModelAttribute("giftCardInfoForm") GiftCardInfoForm giftCardInfoForm, BindingResult result) {
    Order cart = CartState.getCart();//ww w.j  a va2  s.co m

    giftCardInfoFormValidator.validate(giftCardInfoForm, result);
    if (!result.hasErrors()) {
        result.reject("giftCardNumber",
                "The Gift Card module is not enabled. Please contact us for more information about our AccountCredit Module (http://www.broadleafcommerce.com/contact)");
    }

    if (!(cart instanceof NullOrderImpl)) {
        model.addAttribute("orderMultishipOptions",
                orderMultishipOptionService.getOrGenerateOrderMultishipOptions(cart));
        model.addAttribute("paymentRequestDTO", dtoTranslationService.translateOrder(cart));
    }

    populateModelWithReferenceData(request, model);

    return getCheckoutView();
}

From source file:org.openmrs.web.controller.concept.ConceptAttributeTypeFormController.java

private String retireConceptAttributeType(WebRequest request, ConceptAttributeType conceptAttributeType,
        BindingResult errors) {
    String retireReason = request.getParameter("retireReason");
    if (conceptAttributeType.getId() != null && !(StringUtils.hasText(retireReason))) {
        errors.reject("retireReason", "general.retiredReason.empty");
        return null;
    }//w ww.j  a va 2 s . co  m
    Context.getConceptService().retireConceptAttributeType(conceptAttributeType, retireReason);
    request.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
            Context.getMessageSourceService().getMessage("ConceptAttributeType.retired"),
            WebRequest.SCOPE_SESSION);
    return CONCEPT_ATTRIBUTE_TYPES_LIST_URL;
}

From source file:org.openmrs.module.billing.web.controller.main.TenderBillAddController.java

private void validateQty(Integer[] ids, BindingResult binding, HttpServletRequest request) {
    for (int id : ids) {
        try {//from ww w  . j a  va  2 s . c  om
            Integer.parseInt(request.getParameter(id + "_qty"));
        } catch (Exception e) {
            binding.reject("billing.bill.quantity.invalid", "Quantity is invalid");
            return;
        }

    }
}

From source file:org.openmrs.module.billing.web.controller.main.AmbulanceBillAddController.java

private void validate(Integer[] ids, BindingResult binding, HttpServletRequest request) {
    for (int id : ids) {
        try {//from   w w w  . ja va2s . c  om
            Integer.parseInt(request.getParameter(id + "_numOfTrip"));
        } catch (Exception e) {
            binding.reject("billing.bill.quantity.invalid", "Number of trip is invalid");
            return;
        }
        try {
            new BigDecimal(request.getParameter(id + "_amount"));
        } catch (Exception e) {
            binding.reject("billing.bill.quantity.invalid", "Amount is invalid");
            return;
        }

    }
}

From source file:org.openmrs.module.billing.web.controller.main.BillableServiceBillAddController.java

private void validate(Integer[] ids, BindingResult binding, HttpServletRequest request) {
    for (int id : ids) {
        try {/*from  w w  w . j a v  a  2  s  .  co m*/
            Integer.parseInt(request.getParameter(id + "_qty"));
        } catch (Exception e) {
            binding.reject("billing.bill.quantity.invalid", "Quantity is invalid");
            return;
        }
    }
}

From source file:org.openmrs.web.controller.encounter.EncounterRoleFormController.java

/**
 * @param session       HttpSession for the user
 * @param encounterRole encounterRole object submitted from the form
 * @param errors        list of errors if exists   @return logical view name to resolve
 * @throws Exception// w  ww  .  ja  va 2 s .  c  o m
 * @should retire an existing encounter
 * @should raise an error if retire reason is not filled
 */
@RequestMapping(value = ENCOUNTERS_PATH + "encounterRole.form", method = RequestMethod.POST, params = "retire")
public String retire(HttpSession session, @ModelAttribute("encounterRole") EncounterRole encounterRole,
        BindingResult errors) throws Exception {
    new EncounterRoleValidator().validate(encounterRole, errors);
    if (encounterRole.getEncounterRoleId() != null && !(hasText(encounterRole.getRetireReason()))) {
        errors.reject("retireReason", "general.retiredReason.empty");
    }
    if (!errors.hasErrors() && Context.isAuthenticated()) {
        EncounterService service = Context.getEncounterService();
        String message = retireEncounterRole(encounterRole, service);
        session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, message);
        return showEncounterList();
    }

    return showForm();
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormController.java

/**
 * Check if Obs is Valid//from  www . ja  v  a 2s. co  m
 * 
 * @param obs to be validated
 * @param obsErrors the result of the parameter binding
 * @param editReason reason why the obs was edited
 * @return true if obs is valid
 * @should return true if obs is valid
 * @should return false if edit reason is empty and obs id not null
 * @should return false if edit reason is null and obs id not null
 * @should return false if validation of the obs validator fails
 */
private boolean isObsValidToSave(Obs obs, BindingResult obsErrors, String editReason) {
    if (obs.getObsId() != null && (editReason == null || editReason.isEmpty())) {
        obsErrors.reject("editReason", "Obs.edit.reason.empty");
        return false;
    }

    new ObsValidator().validate(obs, obsErrors);
    if (obsErrors.hasErrors()) {
        return false;
    }
    return true;
}

From source file:org.apache.shiro.samples.sprhib.web.SecurityController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(Model model, @ModelAttribute LoginCommand command, BindingResult errors) {
    loginValidator.validate(command, errors);

    if (errors.hasErrors()) {
        return showLoginForm(model, command);
    }//from  ww  w . j  a v a 2s. co  m

    UsernamePasswordToken token = new UsernamePasswordToken(command.getUsername(), command.getPassword(),
            command.isRememberMe());
    try {
        SecurityUtils.getSubject().login(token);
    } catch (AuthenticationException e) {
        errors.reject("error.login.generic", "Invalid username or password.  Please try again.");
    }

    if (errors.hasErrors()) {
        return showLoginForm(model, command);
    } else {
        return "redirect:/s/home";
    }
}

From source file:org.openmrs.module.billing.web.controller.main.ServiceManageController.java

private void validate(Integer[] concepts, HttpServletRequest request, BindingResult binding) {
    for (int conId : concepts) {
        String price = request.getParameter(conId + "_price");
        String name = request.getParameter(conId + "_name");
        if (StringUtils.isNotBlank(price)) {

            try {
                new BigDecimal(price);
            } catch (Exception e) {
                binding.reject("billing.service.price.invalid", "Invalid price for " + name);
                return;
            }//from   www .  j  a  v a  2  s.com
        }
    }
}

From source file:org.xinta.eazycode.components.shiro.web.controller.SecurityController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(Model model, @ModelAttribute LoginVO command, BindingResult errors) {

    loginValidator.validate(command, errors);

    if (errors.hasErrors()) {
        return showLoginForm(model, command);
    }/*from  w ww.j a v  a2s.  co  m*/

    UsernamePasswordToken token = new UsernamePasswordToken(command.getLoginName(), command.getPassword(),
            command.isRememberMe());
    try {
        SecurityUtils.getSubject().login(token);
    } catch (AuthenticationException e) {
        errors.reject("error.login.generic", "Invalid username or password.  Please try again.");
    }

    if (errors.hasErrors()) {
        return showLoginForm(model, command);
    } else {
        return "redirect:/home.do";
    }
}