Java 如何使用GWT编辑器框架使用hibernate validator验证整数

Java 如何使用GWT编辑器框架使用hibernate validator验证整数,java,gwt,hibernate-validator,Java,Gwt,Hibernate Validator,我正在使用hibernate validator和编辑器框架来验证GWT项目中DTO的输入 我遇到的问题是,用户在文本框中输入一个字符串,应该将其验证为整数。我曾尝试应用hibernate验证器注释来自动使其工作,但似乎我遗漏了一些东西 我的DTO: public class MyDto { @Min(value = 1, message = "Radius must be at least 1 meter.") private int radius = 100; ...

我正在使用hibernate validator和编辑器框架来验证GWT项目中DTO的输入

我遇到的问题是,用户在文本框中输入一个字符串,应该将其验证为整数。我曾尝试应用hibernate验证器注释来自动使其工作,但似乎我遗漏了一些东西

我的DTO:

public class MyDto {  
   @Min(value = 1, message = "Radius must be at least 1 meter.")
   private int radius = 100;

   ...
}
我正在使用GWT IntegerBox读取半径的值,当输入值(如-1)时,这会正常工作,但当我输入的值不是整数时,则不会正常工作,例如“hi”

我发现验证这一点的唯一方法是在IntegerBox上发出getValueOrThrow(),然后手动设置错误。没有办法直接使用hibernate验证器注释来表达这一点吗

我尝试过使用整数和@NotNull、@NotEmpty、@Valid

我当前的代码如下所示:

try {
    radiusBox.getValueOrThrow();
}
catch (final ParseException e) {
    radiusDecorator.setErrorText("Invalid radius value.");
    return;
}

final MyDto dto = editorDriver.flush();
final Set<ConstraintViolation<?>> violations = clientValidator.validate(dto);

if (!violations.isEmpty()) {
    editorDriver.setConstraintViolations(violations)
    return;
}
试试看{
radiusBox.getValueOrThrow();
}
捕获(最终解析异常){
radiudecorator.setErrorText(“无效的半径值”);
返回;
}
final MyDto dto=editorDriver.flush();

最后一组我想您想使用hibernate验证器()使用客户端bean验证吗?那么这两个注释(
@NotNull
@NotEmpty
@Valid
)都不起作用了吗?如果不调用GetValueorRow,MyDto中将设置什么值?