开发者

i18n and Java validation annotation messages

I've got the following annotation:

@NotEmpty
@Documented
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = SupportedVideoUrlValida开发者_运维百科tor.class)
public @interface SupportedVideoUrl {
    String message() default "{cast.submission.error.video}";

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

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

    String value() default "";
}

It works OK except the i18n part. The post-validation error message is displayed as is. I do not know how to handle this...

If you have any ideas, thanks in advance for your help!

Rolf


Assuming you are using JSR-303 annontations, put a file ValidationMessages.properties at the root of your classpath containing:

cast.submission.error.video=Video URL is not supported.

this file is loaded as a ResourceBundle so if you need message for a different language add the language suffix to the file (eg ValidationMessages_de.properties for german translations).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜