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


/ Published in: Groovy
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.