ljessendk / easybinder

Apache License 2.0
6 stars 4 forks source link

Accessing error messages from binder or notification #5

Closed NBau closed 6 years ago

NBau commented 7 years ago

currently it is not possible to get the list of error messages from a binder or a notification. As far as I can see, the BasicBinder has all ConstraintViolations (but not accessible from the outside) and the bindings each store conversion and validation error messages. Ideally, the BinderStatusChangeEvent would carry the actual error messages and they would also be accessibe from the binder in an accumulated way.

ljessendk commented 7 years ago

As a first step, I've added a public method to get the constraint violations (4b0f766edcd782b53ec6af1b5b2da41c01d0d4a1).

So you can get the field level conversion and validation errors using: binder.getBindings().stream().map(e -> e.validate()).collect(Collectors.toList()), And the bean level validation errors using: binder.getConstraintViolations().stream().filter(e -> e.getPropertyPath().toString().equals("")) .map(e -> ValidationResult.error(e.getMessage())).collect(Collectors.toList())); Or, alternatively, use the BinderAdapter that exposes a Binder compatible interface including BinderValidationStatus handling.

I'll try to add some logic similar to the BinderValidationStatus handling in Binder to BasicBinder in the near future.

NBau commented 7 years ago

Excellent. Thank you for the quick reply and the good work.

ljessendk commented 6 years ago

Part of release 0.5