/** * Reject the given field with the given error code if the value is empty * or just contains whitespace. * <p>An 'empty' value in this context means either {@code null}, * the empty string "", or consisting wholly of whitespace. * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key */ public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode) { rejectIfEmptyOrWhitespace(errors, field, errorCode, null, null); }
/** * Reject the given field with the given error code and default message * if the value is empty or just contains whitespace. * <p>An 'empty' value in this context means either {@code null}, * the empty string "", or consisting wholly of whitespace. * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key * @param defaultMessage fallback default message */ public static void rejectIfEmptyOrWhitespace( Errors errors, String field, String errorCode, String defaultMessage) { rejectIfEmptyOrWhitespace(errors, field, errorCode, null, defaultMessage); }
/** * Reject the given field with the given error code if the value is empty * or just contains whitespace. * <p>An 'empty' value in this context means either {@code null}, * the empty string "", or consisting wholly of whitespace. * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key */ public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode) { rejectIfEmptyOrWhitespace(errors, field, errorCode, null, null); }
/** * Reject the given field with the given error code and default message * if the value is empty or just contains whitespace. * <p>An 'empty' value in this context means either {@code null}, * the empty string "", or consisting wholly of whitespace. * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key * @param defaultMessage fallback default message */ public static void rejectIfEmptyOrWhitespace( Errors errors, String field, String errorCode, String defaultMessage) { rejectIfEmptyOrWhitespace(errors, field, errorCode, null, defaultMessage); }
/** * Reject the given field with the given error code and error arguments * if the value is empty or just contains whitespace. * <p>An 'empty' value in this context means either {@code null}, * the empty string "", or consisting wholly of whitespace. * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key * @param errorArgs the error arguments, for argument binding via MessageFormat * (can be {@code null}) */ public static void rejectIfEmptyOrWhitespace( Errors errors, String field, String errorCode, @Nullable Object[] errorArgs) { rejectIfEmptyOrWhitespace(errors, field, errorCode, errorArgs, null); }
public void validate(Object obj, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardName", "creditCardName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardNumber", "creditCardNumber.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardCvvCode", "creditCardCvvCode.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpMonth", "creditCardExpMonth.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpYear", "creditCardExpYear.required"); } }
@Override public void validate(Object target, Errors errors) { GiftCardInfoForm giftCardInfoForm = (GiftCardInfoForm) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "giftCardNumber", "giftCardNumber.required"); //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "giftCardEmailAddress", "giftCardEmailAddress.required"); //if (!errors.hasErrors()) { // if (!GenericValidator.isEmail(giftCardInfoForm.getGiftCardEmailAddress())) { // errors.rejectValue("giftCardEmailAddress", "giftCardEmailAddress.invalid", null, null); // } //} } }
public void validate(final Object object, final Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "trackingId", "error.required", "Required"); }
/** * Reject the given field with the given error code and error arguments * if the value is empty or just contains whitespace. * <p>An 'empty' value in this context means either {@code null}, * the empty string "", or consisting wholly of whitespace. * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key * @param errorArgs the error arguments, for argument binding via MessageFormat * (can be {@code null}) */ public static void rejectIfEmptyOrWhitespace( Errors errors, String field, String errorCode, @Nullable Object[] errorArgs) { rejectIfEmptyOrWhitespace(errors, field, errorCode, errorArgs, null); }
public void validate(Object obj, Errors errors) { super.validate(obj, errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.stateProvinceRegion", "state.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.postalCode", "postalCode.required"); }
public void validate(Object obj, Errors errors) { super.validate(obj, errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.stateProvinceRegion", "state.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.postalCode", "postalCode.required"); } }
public void validate(Object obj, Errors errors) { super.validate(obj, errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.stateProvinceRegion", "state.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.postalCode", "postalCode.required"); }
@Override public void validate(Object obj, Errors errors) { super.validate(obj, errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paymentName", "savedPayments.paymentName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paymentToken", "savedPayments.paymentToken.required"); }
public void validate(Object obj, Errors errors) { super.validate(obj, errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.stateProvinceRegion", "state.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.postalCode", "postalCode.required"); }
@Override public void validate(@Nullable Object obj, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "EMPTY_OR_WHITESPACE", "You must enter a name!"); } }
@Override public void validate(Object obj, Errors errors) { PaymentInfoForm paymentInfoForm = (PaymentInfoForm) obj; if (paymentInfoForm.getShouldUseCustomerPayment()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "customerPaymentId", "checkout.paymentMethod.customerPaymentId.required"); } else { super.validate(obj, errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); } } }
public void validate(Object obj, Errors errors) { ShippingInfoForm shippingInfoForm = (ShippingInfoForm) obj; super.validate(BroadleafFormType.SHIPPING_FORM, shippingInfoForm.getAddress(), errors); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fulfillmentOptionId", "fulfillmentOptionId.required"); } }
/** * Validates the {@link UserForm}. * * @param errors * @param userManagement */ default void validate(BindingResult errors, UserManagement userManagement) { rejectIfEmptyOrWhitespace(errors, "username", "user.username.empty"); rejectIfEmptyOrWhitespace(errors, "password", "user.password.empty"); rejectIfEmptyOrWhitespace(errors, "repeatedPassword", "user.repeatedPassword.empty"); if (!getPassword().equals(getRepeatedPassword())) { errors.rejectValue("repeatedPassword", "user.password.no-match"); } try { userManagement.findByUsername(new Username(getUsername())).ifPresent( user -> errors.rejectValue("username", "user.username.exists")); } catch (IllegalArgumentException o_O) { errors.rejectValue("username", "user.username.invalidFormat"); } } }
public void validate(Object obj, Errors errors) { OrderInfoForm orderInfoForm = (OrderInfoForm) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); if (!errors.hasErrors()) { if (!EmailValidator.getInstance().isValid(orderInfoForm.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); } } } }
@Test public void testValidationUtilsEmptyOrWhitespaceVariants() { TestBean tb = new TestBean(); tb.setName(" "); Errors errors = new BeanPropertyBindingResult(tb, "tb"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "EMPTY_OR_WHITESPACE", new Object[] {"arg"}); assertTrue(errors.hasFieldErrors("name")); assertEquals("EMPTY_OR_WHITESPACE", errors.getFieldError("name").getCode()); assertEquals("arg", errors.getFieldError("name").getArguments()[0]); errors = new BeanPropertyBindingResult(tb, "tb"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "EMPTY_OR_WHITESPACE", new Object[] {"arg"}, "msg"); assertTrue(errors.hasFieldErrors("name")); assertEquals("EMPTY_OR_WHITESPACE", errors.getFieldError("name").getCode()); assertEquals("arg", errors.getFieldError("name").getArguments()[0]); assertEquals("msg", errors.getFieldError("name").getDefaultMessage()); }