File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
src/main/java/org/javawebstack/validator/rule Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 1515@ Target (ElementType .FIELD )
1616@ Retention (RetentionPolicy .RUNTIME )
1717public @interface RequiredRule {
18+ boolean allowEmptyStrings () default false ;
19+
1820 class Validator implements ValidationRule {
19- public Validator (RequiredRule rule ) {} // needed
21+ private final boolean allowEmptyStrings ;
22+ public Validator (RequiredRule rule ) {
23+ this .allowEmptyStrings = rule .allowEmptyStrings ();
24+ }
2025
21- public Validator () {}
26+ public Validator (boolean allowEmptyStrings ) {
27+ this .allowEmptyStrings = allowEmptyStrings ;
28+ }
29+
30+ public Validator () {
31+ this .allowEmptyStrings = false ;
32+ }
2233
2334 public String validate (ValidationContext context , Field field , AbstractElement value ) {
24- return !value .isNull () ? null : "Missing required field" ;
35+ if (value .isNull ())
36+ return "Missing required field" ;
37+ if (value .getType () == AbstractElement .Type .STRING && !allowEmptyStrings && value .string ().length () == 0 )
38+ return "Missing required field" ;
39+ return null ;
2540 }
2641 }
2742}
You can’t perform that action at this time.
0 commit comments