Java 在表单验证期间,当值为空时也显示错误消息
我遇到的问题甚至可以在这里的官方SmartGWT演示中看到: 如果输入nothing(将字段留空)并按validate,则不会显示任何错误。对于必需的值,我需要显示错误,即使字段为空 我将验证器设置为:Java 在表单验证期间,当值为空时也显示错误消息,java,gwt,smartgwt,Java,Gwt,Smartgwt,我遇到的问题甚至可以在这里的官方SmartGWT演示中看到: 如果输入nothing(将字段留空)并按validate,则不会显示任何错误。对于必需的值,我需要显示错误,即使字段为空 我将验证器设置为: RegExpValidator regExpValidator = new RegExpValidator(); regExpValidator.setExpression("^[0-9A-Z_]{7,12}$"); regExpValidator.setErro
RegExpValidator regExpValidator = new RegExpValidator();
regExpValidator.setExpression("^[0-9A-Z_]{7,12}$");
regExpValidator.setErrorMessage("Code must contain capital letters and numbers");
codeField.setValidators(regExpValidator);
现在,此表达式与空字符串不匹配。然而,我在验证时没有发现错误
如何在表单中显示空必需值的错误?您可以直接使用setError方法。然后把表格还给我
if(codeField.getText().trim().isEmpty()){
codeField.setError("The Code must not be Empty.");
return;
}
这将返回表单并验证空字符串。是的,我可以这样做,但是当我有验证器时,必须手动验证值似乎很愚蠢。