Validation GWT验证i18n
我希望下面的方法可以奏效:Validation GWT验证i18n,validation,gwt,internationalization,Validation,Gwt,Internationalization,我希望下面的方法可以奏效: @Size(min = 1, message = "{my.custom.message}") private String name; 使用我的源路径中的ValidationMessages.properties,以及我的其他文本资源: my.custom.message=it is kinda short …但是约束冲突仍然读取{my.custom.message} 您是否需要做一些特殊的事情来获取ValidationMessages.properties文件
@Size(min = 1, message = "{my.custom.message}")
private String name;
使用我的源路径中的ValidationMessages.properties,以及我的其他文本资源:
my.custom.message=it is kinda short
…但是约束冲突仍然读取{my.custom.message}
您是否需要做一些特殊的事情来获取ValidationMessages.properties文件?请问这些文件在哪里
很明显,它应该能工作,不知何故:多亏了我在我的项目中设法使它工作
简言之
…定义MyCustomValidationMessages接口:
public interface MyCustomValidationMessages extends com.google.gwt.i18n.client.ConstantsWithLookup {
@DefaultStringValue("NotNull constraint violated")
@Key("notNull")
String notNull();
@DefaultStringValue("Size constraint violated")
@Key("size")
String size();
}
public class MyCustomValidationMessagesResolver extends AbstractValidationMessageResolver
implements UserValidationMessagesResolver {
public MyCustomValidationMessagesResolver() {
super(GWT.create(MyCustomValidationMessages.class));
}
}
…在其旁边创建MyCustomValidationMessages。属性:
notNull=must not be null
size=must be at least {min} characters long
…定义MyCustomValidationMessagesResolver类并使其使用MyCustomValidationMessages接口中的消息:
public interface MyCustomValidationMessages extends com.google.gwt.i18n.client.ConstantsWithLookup {
@DefaultStringValue("NotNull constraint violated")
@Key("notNull")
String notNull();
@DefaultStringValue("Size constraint violated")
@Key("size")
String size();
}
public class MyCustomValidationMessagesResolver extends AbstractValidationMessageResolver
implements UserValidationMessagesResolver {
public MyCustomValidationMessagesResolver() {
super(GWT.create(MyCustomValidationMessages.class));
}
}
…在您的AmazingModule.gwt.xml中使用MyCustomValidationMessagesResolver覆盖UserValidationMessagesResolver的使用:
<replace-with class="amazing.project.client.MyCustomValidationMessagesResolver">
<when-type-is class="com.google.gwt.validation.client.UserValidationMessagesResolver"/>
</replace-with>
瞧
如果你确信你已经做了所有的事情,但是它不起作用,试着删除GWT的临时文件夹并重新启动你的IDE。有时仅仅重建项目并重新启动codeserver(在Idea中)可能是不够的#皮塔