/** * Adds an error to this form. * * @param key the error key * @param error the error message * @param args the errot arguments */ public void reject(String key, String error, List<Object> args) { reject(new ValidationError(key, error, args)); }
/** * @param key the error key * @param error the error message * @param args the error arguments * * @return a copy of this form with the given error added. */ public Form<T> withError(final String key, final String error, final List<Object> args) { return withError(new ValidationError(key, error, args != null ? new ArrayList<>(args) : new ArrayList<>())); }
/** * @param key the error key * @param error the error message * @param args the error arguments * * @return a copy of this form with the given error added. */ public Form<T> withError(final String key, final String error, final List<Object> args) { return withError(new ValidationError(key, error, args != null ? new ArrayList<>(args) : new ArrayList<>())); }
/** * @param key the error key * @param error the error message * @param args the error arguments * * @return a copy of this form with the given error added. */ public Form<T> withError(final String key, final String error, final List<Object> args) { return withError(new ValidationError(key, error, args != null ? new ArrayList<>(args) : new ArrayList<>())); }
/** * Adds a global error to this form. * * @param error the error message * @param args the errot arguments */ public void reject(String error, List<Object> args) { reject(new ValidationError("", error, args)); }
/** * Adds an error to this form. * * @param key the error key * @param error the error message * @param args the error arguments */ public void reject(String key, String error, List<Object> args) { reject(new ValidationError(key, error, args)); }
/** * Adds a global error to this form. * * @param error the error message * @param args the errot arguments */ public void reject(String error, List<Object> args) { reject(new ValidationError("", error, args)); }
private List<ValidationError> globalErrorsAsValidationErrors(BindingResult result) { return result.getGlobalErrors() .stream() .map(error -> new ValidationError( "", error.getDefaultMessage(), convertErrorArguments(error.getArguments()) ) ).collect(Collectors.toList()); }
private List<ValidationError> globalErrorsAsValidationErrors(BindingResult result) { return result.getGlobalErrors() .stream() .map(error -> new ValidationError( "", error.getDefaultMessage(), convertErrorArguments(error.getArguments()) ) ).collect(Collectors.toList()); }
private List<ValidationError> globalErrorsAsValidationErrors(BindingResult result) { return result.getGlobalErrors() .stream() .map(error -> new ValidationError( "", error.getDefaultMessage(), convertErrorArguments(error.getArguments()) ) ).collect(Collectors.toList()); }
private List<ValidationError> getFieldErrorsAsValidationErrors(Lang lang, BindingResult result) { return result.getFieldErrors().stream().map(error -> { String key = error.getObjectName() + "." + error.getField(); if (key.startsWith("target.") && rootName == null) { key = key.substring(7); } if (error.isBindingFailure()) { ImmutableList.Builder<String> builder = ImmutableList.builder(); final Messages msgs = lang != null ? new MessagesImpl(lang, this.messagesApi) : null; for (String code: error.getCodes()) { code = REPLACE_TYPEMISMATCH.matcher(code).replaceAll(Matcher.quoteReplacement(INVALID_MSG_KEY)); if (msgs == null || msgs.isDefinedAt(code)) { builder.add(code); } } final ImmutableList<String> messages = builder.build(); return new ValidationError(key, messages.isEmpty() ? Arrays.asList(INVALID_MSG_KEY) : messages.reverse(), convertErrorArguments(error.getArguments())); } else { return new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); } }).collect(Collectors.toList()); }
private List<ValidationError> getFieldErrorsAsValidationErrors(Lang lang, BindingResult result) { return result.getFieldErrors().stream().map(error -> { String key = error.getObjectName() + "." + error.getField(); if (key.startsWith("target.") && rootName == null) { key = key.substring(7); } if (error.isBindingFailure()) { ImmutableList.Builder<String> builder = ImmutableList.builder(); final Messages msgs = lang != null ? new MessagesImpl(lang, this.messagesApi) : null; for (String code: error.getCodes()) { code = REPLACE_TYPEMISMATCH.matcher(code).replaceAll(Matcher.quoteReplacement(INVALID_MSG_KEY)); if (msgs == null || msgs.isDefinedAt(code)) { builder.add(code); } } final ImmutableList<String> messages = builder.build(); return new ValidationError(key, messages.isEmpty() ? Arrays.asList(INVALID_MSG_KEY) : messages.reverse(), convertErrorArguments(error.getArguments())); } else { return new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); } }).collect(Collectors.toList()); }
private List<ValidationError> getFieldErrorsAsValidationErrors(Lang lang, BindingResult result) { return result.getFieldErrors().stream().map(error -> { String key = error.getObjectName() + "." + error.getField(); if (key.startsWith("target.") && rootName == null) { key = key.substring(7); } if (error.isBindingFailure()) { ImmutableList.Builder<String> builder = ImmutableList.builder(); final Messages msgs = lang != null ? new MessagesImpl(lang, this.messagesApi) : null; for (String code: error.getCodes()) { code = REPLACE_TYPEMISMATCH.matcher(code).replaceAll(Matcher.quoteReplacement(INVALID_MSG_KEY)); if (msgs == null || msgs.isDefinedAt(code)) { builder.add(code); } } final ImmutableList<String> messages = builder.build(); return new ValidationError(key, messages.isEmpty() ? Arrays.asList(INVALID_MSG_KEY) : messages.reverse(), convertErrorArguments(error.getArguments())); } else { return new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); } }).collect(Collectors.toList()); }
errors.put(key, new ArrayList<ValidationError>()); errors.get(key).add(new ValidationError(key, error.isBindingFailure() ? "error.invalid" : error.getDefaultMessage(), arguments)); if(globalError instanceof String) { errors.put("", new ArrayList<ValidationError>()); errors.get("").add(new ValidationError("", (String)globalError, new ArrayList())); } else if(globalError instanceof List) { for (ValidationError error : (List<ValidationError>) globalError) {
builder.add( code.replace("typeMismatch", "error.invalid") ); validationError = new ValidationError(key, builder.build(), convertErrorArguments(error.getArguments())); } else { validationError = new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); globalErrors.add(new ValidationError("", error.getDefaultMessage(), convertErrorArguments(error.getArguments()))); if (globalError instanceof String) { errors.put("", new ArrayList<ValidationError>()); errors.get("").add(new ValidationError("", (String)globalError, new ArrayList())); } else if (globalError instanceof List) { for (ValidationError error : (List<ValidationError>) globalError) {
@Override public DynamicForm withError(final ValidationError error) { final Form<Dynamic> form = super.withError(new ValidationError(asDynamicKey(error.key()), error.messages(), error.arguments())); return new DynamicForm(super.rawData(), super.files(), form.errors(), form.value(), this.messagesApi, this.formatters, this.validatorFactory, this.config, lang().orElse(null)); }
@Override public DynamicForm withError(final ValidationError error) { final Form<Dynamic> form = super.withError(new ValidationError(asDynamicKey(error.key()), error.messages(), error.arguments())); return new DynamicForm(super.rawData(), super.files(), form.errors(), form.value(), this.messagesApi, this.formatters, this.validatorFactory, this.config, lang().orElse(null)); }
@Override public DynamicForm withError(final ValidationError error) { final Form<Dynamic> form = super.withError(new ValidationError(asDynamicKey(error.key()), error.messages(), error.arguments())); return new DynamicForm(super.rawData(), super.files(), form.errors(), form.value(), this.messagesApi, this.formatters, this.validatorFactory, this.config, lang().orElse(null)); }