|
Hello everyone
With Grails 1.3.7 I used to write code like that: class TestController { def index = { } def apply = { ApplyCommand cmd -> if (cmd.hasErrors()) { log.error(cmd.errors.errorCount + " errors detected!") render(view: 'index') return } flash.message = 'ok' redirect(action: 'index') } } class ApplyCommand { String fooParam static constraints = { fooParam(blank: false, minSize: 3) } } index.gsp: <g:hasErrors> <div class="errors"> <g:renderErrors as="list" codec="none"/> </div> </g:hasErrors> <g:if test="${flash.message}"> <div class="message">${flash.message}</div> </g:if> Everything worked well, means if fooParams does not meet the constraints, the log statement executes and the GSP renders the error message: "Property [fooParam] of class [class grails.test.ApplyCommand] cannot be blank". In Controllers I used also the reject method, e.g. to render exceptions from a legacy java api: cmd.errors.reject("i18n.message.code", [errArg1, errArg2] as Object[], "default errorMsg") This worked fine too. But now with Grails 2.0.3 something must have changed: cmd.hasErrors() works still as expected in the Controller, but in the GSP no error is rendered. I liked the simplicity of the <g:hasErrors> and <g:renderErrors> tags with no attributes (e.g. bean nor model) since code like that is generic and worked for every kind of errors (whether from a domain or a command object). According to the docs both tags still have only optional attributes, so I think this should work like in Grails 1.3. I appreciate if someone could explain me what I'm doing (or understanding) wrong here. Many thanks, Markus --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
nobody ran into this problem?
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by MarkusE
I found a solution: If I pass a model which includes the command object to the render method, the error gets rendered again. render(view: 'index', model: [dummy: cmd]) So, I assume in Grails 1.3 any command object was implicitly included to the model which was rendered, but since Grails 2 this is no longer the case. Can someone clarify – is this the desired behavior? Thanks http://grails.1312388.n4.nabble.com/Rendering-errors-of-a-CommandObject-td4592885.html -----Ursprüngliche Nachricht----- Hello everyone With Grails 1.3.7 I used to write code like that: class TestController { def index = { } def apply = { ApplyCommand cmd -> if (cmd.hasErrors()) { log.error(cmd.errors.errorCount + " errors detected!") render(view: 'index') return } flash.message = 'ok' redirect(action: 'index') } } class ApplyCommand { String fooParam static constraints = { fooParam(blank: false, minSize: 3) } } index.gsp: <g:hasErrors> <div class="errors"> <g:renderErrors as="list" codec="none"/> </div> </g:hasErrors> <g:if test="${flash.message}"> <div class="message">${flash.message}</div> </g:if> Everything worked well, means if fooParams does not meet the constraints, the log statement executes and the GSP renders the error message: "Property [fooParam] of class [class grails.test.ApplyCommand] cannot be blank". In Controllers I used also the reject method, e.g. to render exceptions from a legacy java api: cmd.errors.reject("i18n.message.code", [errArg1, errArg2] as Object[], "default errorMsg") This worked fine too. But now with Grails 2.0.3 something must have changed: cmd.hasErrors() works still as expected in the Controller, but in the GSP no error is rendered. I liked the simplicity of the <g:hasErrors> and <g:renderErrors> tags with no attributes (e.g. bean nor model) since code like that is generic and worked for every kind of errors (whether from a domain or a command object). According to the docs both tags still have only optional attributes, so I think this should work like in Grails 1.3. I appreciate if someone could explain me what I'm doing (or understanding) wrong here. Many thanks, Markus --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
