我有一個下拉框和一個TextField。文本字段的值必須以唯一編號開頭,具體取決於所選內容。如果不顯示錯誤消息。錯誤消息中的變量
根據選擇的錯誤信息是這樣的:
在「文本字段」的數量必須以101開頭的選擇1
或
在「文本字段」的個數必須開始與102,用於選擇2
等
我已經寫自定義驗證來驗證的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}
是變量。
這可能嗎?
謝謝。