Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34659 > unrolled thread

Problem with validation

Started byCecil Westerhof <Cecil@decebal.nl>
First post2016-06-16 08:08 +0200
Last post2016-06-16 14:25 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Problem with validation Cecil Westerhof <Cecil@decebal.nl> - 2016-06-16 08:08 +0200
    Re: Problem with validation Lew <lewbloch@gmail.com> - 2016-06-16 14:25 -0700

#34659 — Problem with validation

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-06-16 08:08 +0200
SubjectProblem with validation
Message-ID<8760t97jjm.fsf@Equus.decebal.nl>
We have a strange problem with validation. We defined the following
annotation:
    @Documented
    @Constraint(validatedBy = {})
    @Target({ FIELD })
    @Retention(RUNTIME)
    @ReportAsSingleViolation
    @NotNull
    @Size(min = 1)
    public @interface NotEmpty {
        // default
        final static String errorMessage = "Field is not allowed to be empty";

        Class<?>[] groups() default {};

        String message() default errorMessage;

        Class<? extends Payload>[] payload() default {};
    }

We have this annotation defined on 8 fields, like:
    @NotEmpty(message = "ZIP-code is not allowed to be empty")

Only one field (the one with the ZIP-code) is empty, but when we call
persist we get a validation exception of five of them. When we print
the name of the field, the message and the invalid value, we see it is
the NotEmpty annotation that fired and that except for ZIP-code the
fields are filled. ZIP-code contains the empty string.

Also when we fill ZIP-code the persist does not fire with an
validation exception.

What could be the reason we get a validation exception for four fields
we should not get one for?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#34663

FromLew <lewbloch@gmail.com>
Date2016-06-16 14:25 -0700
Message-ID<78c4568b-e52f-43e2-8027-a4fefa3a00b0@googlegroups.com>
In reply to#34659
Cecil Westerhof wrote:
> We have a strange problem with validation. We defined the following
> annotation:
>     @Documented
>     @Constraint(validatedBy = {})
>     @Target({ FIELD })
>     @Retention(RUNTIME)
>     @ReportAsSingleViolation
>     @NotNull
>     @Size(min = 1)
>     public @interface NotEmpty {
>         // default
>         final static String errorMessage = "Field is not allowed to be empty";
> 
>         Class<?>[] groups() default {};
> 
>         String message() default errorMessage;
> 
>         Class<? extends Payload>[] payload() default {};
>     }
> 
> We have this annotation defined on 8 fields, like:
>     @NotEmpty(message = "ZIP-code is not allowed to be empty")
> 
> Only one field (the one with the ZIP-code) is empty, but when we call
> persist we get a validation exception of five of them. When we print
> the name of the field, the message and the invalid value, we see it is
> the NotEmpty annotation that fired and that except for ZIP-code the
> fields are filled. ZIP-code contains the empty string.
> 
> Also when we fill ZIP-code the persist does not fire with an
> validation exception.
> 
> What could be the reason we get a validation exception for four fields
> we should not get one for?

Can you please prepare an SSCCE (Simple, Self-Contained, Compilable Example), per http://sscce.org/ ?

-- 
Lew

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web