현재 Grails 응용 프로그램에서 작업 중이며 도메인 모델의 개체에 대해 표시되는 기본 오류 메시지를 변경하려고합니다. 나는 생각 나는 올바른 모든 짓을하지만 어쩌면 누군가가 나를 아래 코드이 문제를 해결할 수 :Grails Custom Validation 메시지가 작동하지 않습니까?
도메인 모델 :
class Details {
long mobileNo
String name
static constraints = {
mobileNo(blank:false, maxsize:12, matches:"44[0-9]{10}")
}
}
messages.properties
sms.mobileNo.matches.invalid=You must enter a correct mobile number in {0}
보기
이제3210은 (는) 다음과 같은 컨트롤러 기능에가는 페이지를 클릭 만들 :
def details = new Details(params)
if (details.validate()) {
}
else{
render view: 'create', model: [detailsInstance: details]
}
가 지금은 응용 프로그램이이 같은 일을 기대 : 하나는 잘못된 데이터가 컨트롤러에 전달 그것을보고 유효하지 않으며 오류가있는 모델을 다시 같은보기로 전달합니다. 그런 다음 messages.properties 파일에서 오류 메시지가 추출됩니다. 그러나 여기서 나는이를 볼 것으로 예상 :
Failed to convert property value of type java.lang.String to required type long for property mobileNo; nested exception is java.lang.IllegalArgumentException: Could not parse number: Unparseable number: "gg"
사람이 사용자에게 도움이 메시지를 표시하기 위해 검증을위한 사용자 정의 메시지를 생성하도록 도와 주시겠습니까 :
You must enter a correct mobile number in [mobileNo]
내가 대신 볼? 감사합니다.
고맙습니다. 많은 도움을 주셨습니다. 이제 그것을 정렬했습니다 .-D – user723858