我有一个下拉框和一个 TextField。文本字段的值必须以唯一编号开头,具体取决于选择。如果不是,将显示错误消息。
根据选择,错误消息如下所示:
对于 selection1,“TextField”中的数字必须以 101 开头
或者
“TextField”中的数字必须以 102 开头,用于 selection2
等等
我编写了一个自定义验证器来验证 TextField。
我不喜欢的是,对于每个错误,我都有一个资源键及其对应的错误消息值:
@Override
protected void onValidate(IValidatable<String> validatable) {
if(selection.equals(selections1) && !beginsWithGoodNumber){
error(validatable, "error.selection1");
}else if(selection.equals(selections1) && !beginsWithGoodNumber){
error(validatable, "error.selection2");
}else if(selection.equals(selections1) && !beginsWithGoodNumber){
error(validatable, "error.selection3");
}
}
在我的属性文件中:
error.selection1 = the number in the '${label}' must begin with 101 for selection1
error.selection2 = the number in the '${label}' must begin with 102 for selection2
error.selection3 = the number in the '${label}' must begin with 103 for selection3
error.selection4 = the number in the '${label}' must begin with 104 for selection4
我想在属性文件中有这样的东西:
error.selection = the number in the '${label}' must begin with {number} for {selection}
其中{number}
和{selection}
是变量。
这可能吗?
谢谢。