私はBeanの検証に使用javax.validation
しています。JSR-303
検証メソッドを呼び出した後、結果を確認し、GUI で何らかの処理を行います (たとえば、フォームで失敗したフィールドを強調表示するなど)。
ここで私の質問:
MyBean.java
public class MyBean {
@Size(min = 1, message = "Please insert title")
private String title;
@Size(min = 1, message = "Please insert author")
private String author;
@Size(min = 1, message = "Please insert publisher")
private String publisher;
// ... something
}
私の検証方法:
Set<ConstraintViolation<MyBean>> failures = this.validator.validate(bean);
その後、失敗オブジェクトを反復処理します。
for (ConstraintViolation<MyBean> constraintViolation : failures) {
propertyPath = constraintViolation.getPropertyPath().toString();
if (propertyPath.equals("title")) {
Color bg = new Color(242, 242, 251);
this.txtTitle.setBackground(bg);
}
// some else if for other attributes (for example: author)
// add error to all error messages
errorMessage += constraintViolation.getMessage();
}
今私の問題は次のとおりです。失敗セット内のこれらのオブジェクトの順序。それは正しくありません。正しい順序を取得するための解決策はありますか?
ありがとうございます