2013-06-11 2 views
2

나는 드롭 다운 상자와 TextField가 있습니다. 텍스트 필드의 값은 선택 항목에 따라 고유 번호로 시작해야합니다. 그렇지 않으면 오류 메시지가 표시됩니다.오류 메시지의 변수

는 선택에 따라 오류 메시지는 다음과 같습니다

은 "텍스트 필드"의 수는 selection1

또는

은 "텍스트 필드"의 수를 시작해야합니다 위해 101로 시작해야합니다 selection2

에 대한 102 등

내가 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}은 변수입니다.

이것이 가능합니까?

감사합니다.

답변

1

유효성 검사기가 AbstractValidator를 확장한다고 가정하면 변수 맵을 #error()에 전달할 수 있습니다.

또는 ValidationError를 작성하고 변수를 설정 한 다음 구성 요소에보고하는 방법에 대한 AbstractRangeValidator를 참조하십시오.

0

ValidationError 객체를 설정하고 validatable.error 메소드로 설정할 수 있습니다. ValidationError에는 변수를 설정하는 메서드가 있습니다.

관련 문제