2013-02-26 2 views
0

여기에 무엇이 누락되어 있는지 확실하지 않으며, 무언가 어리 석다는 것을 두려워합니다. 아주 간단한 설정, 나는 /reference/save에 게시하고 아무것도 지나치지 않고 있습니다 ... 돌아올 것으로 기대합니다. required error.Documentation은 기본적으로 nullable:true으로되어 있습니다.하지만 그게 정확하지 않다고 생각하기 시작했습니다.instance.validate() true를 반환합니다.

#domain 
class Reference{ 
    String name; 
    String publication; 
    String year; 
    String section; 
    String description; 
    String link; 
    static constraints = { 
     year nullable: true 
     section nullable: true 
     link url: true 
    } 
} 

#controller: 
Reference referenceInstance = new Reference(params) 
println(params) 
println(referenceInstance.validate()) 

출력 :

>>[description:, link:, name:, year:, section:, publication:, action:save, controller:reference] 
>>true 

답변

3

시도는 당신의 재산에 blank 제약 조건을 추가 할 수 있습니다.

params 맵에는 각 속성에 대한 키가 있습니다. Grails는 그들을 null이 아닌 빈 문자열로 취급합니다.

static constraints = { 
    year nullable: true 
    section nullable: true 
    link url: true, blank: false 
    description blank: false 
    name blank: false 
    publication blank: false 
} 
관련 문제