Definiowanie niestandardowych ograniczeÅ
Niestandardowe ograniczenia sÄ projektowane z myÅlÄ o konkretnych kryteriach weryfikacji. Takie ograniczenia można nastÄpnie definiowaÄ, ÅÄ czÄ c adnotacje ograniczeÅ z listami implementacji niestandardowych mechanizmów weryfikacji.
Poniższy fragment definiuje adnotacjÄ niestandardowego ograniczenia umożliwiajÄ cego weryfikacjÄ amerykaÅskich kodów pocztowych:
@Documented @Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER }) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy=ZipCodeValidator.class) @Size(min=5, message="{org.sample.zipcode.min_size}") @Pattern(regexp="[0-9]*") @NotNull(message="{org.sample.zipcode.cannot_be_null}") ...
Get Java EE 6. Leksykon kieszonkowy now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.