/** * Retrieve all global errors - errors without a key. * * @return All global errors. */ public List<ValidationError> globalErrors() { return Collections.unmodifiableList(errors.stream().filter(error -> error.key().isEmpty()).collect(Collectors.toList())); }
/** * Retrieve all global errors - errors without a key. * * @return All global errors. */ public List<ValidationError> globalErrors() { return Collections.unmodifiableList(errors.stream().filter(error -> error.key().isEmpty()).collect(Collectors.toList())); }
/** * Retrieve all global errors - errors without a key. * * @return All global errors. */ public List<ValidationError> globalErrors() { return Collections.unmodifiableList(errors.stream().filter(error -> error.key().isEmpty()).collect(Collectors.toList())); }
/** * @param key the field name associated with the error. * @return All errors for this key. */ public List<ValidationError> errors(String key) { if(key == null) { return Collections.emptyList(); } return Collections.unmodifiableList(errors.stream().filter(error -> error.key().equals(key)).collect(Collectors.toList())); }
/** * @param key the field name associated with the error. * @return All errors for this key. */ public List<ValidationError> errors(String key) { if(key == null) { return Collections.emptyList(); } return Collections.unmodifiableList(errors.stream().filter(error -> error.key().equals(key)).collect(Collectors.toList())); }
/** * @param key the field name associated with the error. * @return All errors for this key. */ public List<ValidationError> errors(String key) { if(key == null) { return Collections.emptyList(); } return Collections.unmodifiableList(errors.stream().filter(error -> error.key().equals(key)).collect(Collectors.toList())); }
/** * Formats the Play error message somehow, with the translation to the first available locale. * As hash arguments, it defines the field key as "field" and all other arguments as its index, e.g. "0", "1", "2". * @param locales current given locales * @param error Play's validation error * @return the error message localized and formatted */ default String format(final List<Locale> locales, final ValidationError error) { final Map<String, Object> args = new HashMap<>(); if (error.key() != null && !error.key().isEmpty()) { args.put("field", error.key()); } IntStream.range(0, error.arguments().size()) .forEach(index -> args.put(String.valueOf(index), error.arguments().get(index))); return format(locales, error.message(), args); } }
@Deprecated public ErrorsBean(final List<Form<?>> filledForms) { this.globalErrors = new ArrayList<>(); filledForms.forEach(filledForm -> filledForm.errors().forEach((field, errors) -> errors.forEach(error -> globalErrors.add(new ErrorBean(field, error.key() + ": " + error.message()))))); }
/** * Returns the form errors serialized as Json using the given Lang. * @param lang the language to use. * @return the JSON node containing the errors. */ public JsonNode errorsAsJson(Lang lang) { Map<String, List<String>> allMessages = new HashMap<>(); errors.forEach(error -> { if (error != null) { final List<String> messages = new ArrayList<>(); if (messagesApi != null && lang != null) { final List<String> reversedMessages = new ArrayList<>(error.messages()); Collections.reverse(reversedMessages); messages.add(messagesApi.get(lang, reversedMessages, translateMsgArg(error.arguments(), messagesApi, lang))); } else { messages.add(error.message()); } allMessages.put(error.key(), messages); } }); return play.libs.Json.toJson(allMessages); }
/** * Returns the form errors serialized as Json using the given Lang. * @param lang the language to use. * @return the JSON node containing the errors. */ public JsonNode errorsAsJson(Lang lang) { Map<String, List<String>> allMessages = new HashMap<>(); errors.forEach(error -> { if (error != null) { final List<String> messages = new ArrayList<>(); if (messagesApi != null && lang != null) { final List<String> reversedMessages = new ArrayList<>(error.messages()); Collections.reverse(reversedMessages); messages.add(messagesApi.get(lang, reversedMessages, translateMsgArg(error.arguments(), messagesApi, lang))); } else { messages.add(error.message()); } allMessages.put(error.key(), messages); } }); return play.libs.Json.toJson(allMessages); }
@BodyParser.Of(play.mvc.BodyParser.Json.class) public static Result editClientJSON() { Logger.debug("Reached editClientJSON"); Form<Client> clientForm = Form.form(Client.class).bindFromRequest(); if(clientForm.hasErrors()) {//check out for form errors for (String errorKey : clientForm.errors().keySet()) { for (ValidationError error : clientForm.errors().get(errorKey)) { Logger.error(error.key() + " = " + error.message()); } } return badRequest(); } //There is no error on the form so it is now safe to get the Client Client client = clientForm.get(); client.update(); Logger.debug("Client updated: " + client.name); response().setHeader(LOCATION, routes.ClientCtrl.getClientJSON(client.id).url()); return ok(); }
/** * Returns the form errors serialized as Json using the given Lang. * @param lang the language to use. * @return the JSON node containing the errors. */ public JsonNode errorsAsJson(Lang lang) { Map<String, List<String>> allMessages = new HashMap<>(); errors.forEach(error -> { if (error != null) { final List<String> messages = new ArrayList<>(); if (messagesApi != null && lang != null) { final List<String> reversedMessages = new ArrayList<>(error.messages()); Collections.reverse(reversedMessages); messages.add(messagesApi.get(lang, reversedMessages, translateMsgArg(error.arguments(), messagesApi, lang))); } else { messages.add(error.message()); } allMessages.put(error.key(), messages); } }); return play.libs.Json.toJson(allMessages); }
final ValidationError error = (ValidationError) dynamicPayload; result.rejectValue( error.key(), violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), error.arguments() != null ? error.arguments().toArray() : new Object[0], ((List<ValidationError>) dynamicPayload).forEach(error -> result.rejectValue( error.key(), violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), error.arguments() != null ? error.arguments().toArray() : new Object[0],
final ValidationError error = (ValidationError) dynamicPayload; result.rejectValue( error.key(), violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), error.arguments() != null ? error.arguments().toArray() : new Object[0], ((List<ValidationError>) dynamicPayload).forEach(error -> result.rejectValue( error.key(), violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), error.arguments() != null ? error.arguments().toArray() : new Object[0],
final ValidationError error = (ValidationError) dynamicPayload; result.rejectValue( error.key(), violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), error.arguments() != null ? error.arguments().toArray() : new Object[0], ((List<ValidationError>) dynamicPayload).forEach(error -> result.rejectValue( error.key(), violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(), error.arguments() != null ? error.arguments().toArray() : new Object[0],
@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)); }