對於當前的項目,我們使用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應用程序中定義和使用自己的註釋,並可以看到我失蹤的內容?
在此先感謝