-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make use of Java type information on annotated fields #24
Comments
Thanks! If you rephrase or redefine the statement
then I'm very fond of this idea, makes a lot of sense. Why not for every field? Based on the list of built-in valdr validators this would currently only be applicable to |
I have amended the proposal according to your suggestion. Implementing said scheme for Integer-types should be straightforward. As for floating point types, I don't see any good way to do this since there is no way to express their domain in terms of a fixed integer and fraction part, as is demanded by
So I guess it boils down to implementing this scheme for integer-types only. With regard to the original motivation, namely that valdr does not know something is a number unless it is annotated in an appropriate way, that would be a start, but it is not totally satisfying. Maybe it is not the right approach for what I want, which basically is for valdr and valdr-messages to know about builtin angularjs validations like |
@marcelstoer It is not part of JSR303, but one way to tell valdr that a field is a number would be to add a simple "number" rule for all sub classes of What do you think about extending this plugin's scope like that? |
I don't think that this helps a lot for the client side validation. If I understand your idea correctly, this would just check that the user enters a number (at least that's what Angulars I would suggest to implement a project specific extension of JSR303 @Digits(integer = MyDecimal.INTEGER, fraction = MyDecimal.FRACTION)
@Retention(RetentionPolicy.RUNTIME)
@Target(FIELD)
@Documented
@Constraint(validatedBy = { })
@ReportAsSingleViolation
public @interface MyDecimal {
int FRACTION = 6;
int INTEGER = 12;
int integer() default MyDecimal.INTEGER;
int fraction() default MyDecimal.FRACTION;
String message() default "{com.application.MyDecimal.message}";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { };
} Client side: .config(function (valdrProvider) {
valdrProvider.addConstraintAlias('digits', 'com.application.MyDecimal');
}) |
One way or the other I think it's important that your markup contains
Depending on what you're actually trying to achieve this could be a pragmatic way to go. To be consistent with existing constraints we'd have to make |
Sorry, I'll try to focus. I have a field
which is part of a form
and I use valdrMessage for showing validation errors. When I enter "a" into this field, valdr does not show a validation error, because it does not know about In this particular case even the generating of the I see two possibilities for solving the above problem:
Thanks for your feedback. |
We have decided to go with Philipp's approach since we think it is too rare a case that a numerical field's value is only limited by its type. As such, information expressed through annotations is usually not redundant, contrary to what I argued in the original post. What we would like to discuss further is support for angular builtin validations in valdrMessage, for which I will open an issue presently. From our point of view there is nothing more to do here. If you do not want to pursue any of the ideas, feel free to close this issue. |
@bjorm I agree that being able to show AngularJS validation errors in valdr message would be a nice improvement. Thanks for opening a feature request for it! |
Currently the only way to tell valdr that a certain field is a number is by annotating it with
@Digits
or some custom annotation. Obviously this introduces some redundancy.What would you think about extending valdr-bean-validation in such a way that for
every field fields of some selected types it scans it also adds validation rules based on its type?scanned fields of a few selected types (tbd) it "generates"/automatically adds rules.Say we have a field
Then its validation rule would look like this:
Thanks for your thoughts on this.
The text was updated successfully, but these errors were encountered: