generate-view ${domainClassWithInURLProperty} 시 Exception

5 views
Skip to first unread message

양완수

unread,
Apr 10, 2012, 12:30:56 AM4/10/12
to KG...@googlegroups.com

class Book {
   ...
   URL url
   ..
}


Book 을 토대로  generate-view 할 때 

아래와 같은 Exception이 발생합니다.

groovy.lang.MissingPropertyException : URL constraint can only be applied to a String property .....
.....

templates/scaffolding/renderEditor.template 을 살펴보니 아래 cp.url 에서 발생하는것이더군요...(html5 지원을 위한 템플릿 같습니다.)

    private renderStringEditor(domainClass, property) {
        if (!cp) {
            return "<g:textField name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
        } else {
			def sb = new StringBuilder("")
            if ("textarea" == cp.widget || (cp.maxSize > 250 && !cp.password && !cp.inList)) {
                sb << '<g:textArea name="' << property.name << '"'
 				sb << ' cols="40" rows="5"'
				if (cp.maxSize) sb << ' maxlength="' << cp.maxSize << '"'
				if (isRequired()) sb << ' required=""'
 				sb << ' value="${' << "${domainInstance}?.${property.name}" << '}"'
				sb << '/>'
            } else if (cp.inList) {
				sb << '<g:select name="' << property.name << '"'
				sb << ' from="${' << "${domainInstance}.constraints.${property.name}.inList" << '}"'
				if (isRequired()) sb << ' required=""'
				sb << ' value="${' << "${domainInstance}?.${property.name}" << '}"'
				sb << ' valueMessagePrefix="' << "${domainClass.propertyName}.${property.name}" << '"'
				sb << renderNoSelection(property)
				sb << '/>'
			} else {
				if (cp.password) {
					sb << '<g:field type="password"'
				} else if (cp.url) {
					sb << '<g:field type="url"'
				} else if (cp.email) {
					sb << '<g:field type="email"'
				} else {
					sb << '<g:textField'
				}
				sb << ' name="' << property.name << '"'
				if (cp.maxSize) sb << ' maxlength="' << cp.maxSize << '"'
				if (!cp.editable) sb << ' readonly="readonly"'
				if (cp.matches) sb << ' pattern="${' << "${domainInstance}.constraints.${property.name}.matches" << '}"'
				if (isRequired()) sb << ' required=""'
				sb << ' value="${' << "${domainInstance}?.${property.name}" << '}"'
				sb << '/>'
			}
			sb as String
        }
    }

org.codehaus.groovy.grails.validation.ConstrainedProperty.isUrl 에 따르면  CharSequence.class.isAssignableFrom(propertyType) 이여야 하고 constraint 에 url 설정을 true 해야 되는것 같습니다.

    public boolean isUrl() {
        if (isNotValidStringType()) {
            throw new MissingPropertyException("URL constraint can only be applied to a String property",
                    URL_CONSTRAINT, owningClass);
        }
        return appliedConstraints.containsKey(URL_CONSTRAINT);
    }


겱국 template 상에서 html5 지원 부분 (email,url)체크부분과 if (cp.matches) ... 이 부분을 주석 처리 하였습니다.


Reply all
Reply to author
Forward
0 new messages