Order of error messages in renderErrors
I've just started creating a new website with Grails and noticed a bug in which between the order of the columns I defined and order of error messages in "g:renderErrors" are different.
I wanted to know how to solve it and make sure if it is a bug or not. Surfing the internet and finally I found a bug report in Grails User Mailing List.
Guess if I'm that hung up on the order and formatting of the errors, I can render each field's errors individually by specifying the field name:
Sorry for the newby error.
ummm.. I don't want to write error messages individually so I modified some scaffolding templates.(GRAILS_HOME/src/grails/templates/scaffolding)
The code is below. If you write like this, you can use a "graills generate-views" or a "generate-all" command and copy a part of some and paste it.
create.gsp(you also need to revise edit.gsp)
<% import org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor as Events %><%=packageName%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta name="layout" content="main" /> <title>Create ${className}</title> </head> <body><% excludedProps = ['version', 'id', Events.ONLOAD_EVENT, Events.BEFORE_DELETE_EVENT, Events.BEFORE_INSERT_EVENT, Events.BEFORE_UPDATE_EVENT] props = domainClass.properties.findAll { !excludedProps.contains(it.name) } Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[])) %> <div class="nav"> <span class="menuButton"><a class="home" href="\${resource(dir:'')}">Home</a></span> <span class="menuButton"><g:link class="list" action="list">${className} List</g:link></span> </div> <div class="body"> <h1>Create ${className}</h1> <g:if test="\${flash.message}"> <div class="message">\${flash.message}</div> </g:if> <g:hasErrors bean="\${${propertyName}}"> <div class="errors"><% props.each { p -> if(!Collection.class.isAssignableFrom(p.type)) { cp = domainClass.constrainedProperties[p.name] display = (cp ? cp.display : true) if(display) { %> <g:renderErrors bean="\${${propertyName}}" as="list" field="${p.name}"/><% } } } %> </div> </g:hasErrors> <g:form action="save" method="post" <%= multiPart ? ' enctype="multipart/form-data"' : '' %>> <div class="dialog"> <table> <tbody><% props.each { p -> if(!Collection.class.isAssignableFrom(p.type)) { cp = domainClass.constrainedProperties[p.name] display = (cp ? cp.display : true) if(display) { %> <tr class="prop"> <td valign="top" class="name"> <label for="${p.name}">${p.naturalName}:</label> </td> <td valign="top" class="value \${hasErrors(bean:${propertyName},field:'${p.name}','errors')}"> ${renderEditor(p)} </td> </tr> <% } } } %> </tbody> </table> </div> <div class="buttons"> <span class="button"><input class="save" type="submit" value="Create" /></span> </div> </g:form> </div> </body> </html>
... I am still waiting for fixing this bug.