Posted By

callmeblessed on 01/02/09


Tagged

error groovy grails


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sfhynx


Grails : How to read error without using g:view (in controller / service)


 / Published in: Groovy
 

how to read error message as string instead of complicated codes. usually people using taglib to read error messages. but how to read it in controller/service if you, for example, want to log or render just the message. here is how to do that.

  1. // in controller/services :
  2. class GrailsService {
  3. boolean transactional = true
  4. def messageSource ;
  5.  
  6. def locale = Locale.getDefault()
  7. domainObj.errors.each { fieldErrors ->
  8. fieldErrors.allErrors.each { error ->
  9. log.warn messageSource.getMessage(error, locale)
  10. }
  11. }
  12.  
  13. }

Report this snippet  

You need to login to post a comment.