[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.java.programmer

Problem with validation

Problem with validation

Cecil Westerhof

6/16/2016 6:08:00 AM

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/ceci...

Lew

6/16/2016 9:26:00 PM

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://... ?

--
Lew

Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Problem with validation

Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te

Il servizio è completamente GRATUITO!