对于当前的项目,我们使用JSR-303注释来验证我们的接口参数。在GWT中使用自定义的javax验证注释
我需要为日期创建自定义注释,因为默认@Past和@Before也会考虑时间。
这是我诠释的定义:
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = { NotInFutureValidator.class })
/**
* Annotated element must be a date before tomorrow, compared to the system's date
*/
public @interface NotInFuture {
String message() default "{be.credoc.contractRegistration.interface_v2.validation.pastignoretime}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
验证的实现是非常直接的。
我们的web应用程序是用GWT编写的,它使用gwt验证。这允许我们通过相同的注释在客户端验证我们的参数。
但是,当我用我的自定义注释注释我的参数,并且我想通过使用GwtValidatorFactory来验证它时,它在输入日期未来时不会给我一个错误。
有没有人遇到过在GWT应用程序中定义和使用自己的注释,并可以看到我失踪的内容?
在此先感谢