Grails - Using codecs in UrlMappings config


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



Copy this code and paste it in your HTML
  1. import org.codehaus.groovy.grails.plugins.codecs.URLCodec
  2.  
  3. class UrlMappings {
  4.  
  5. static mappings = {
  6. // Add the URL encode and decode methods as the codec methods are added
  7. // after the mappings are processed.
  8. final codec = URLCodec.newInstance()
  9. Object.metaClass."encodeAsURL" = { -> codec.encode(delegate) }
  10. Object.metaClass."decodeURL" = { -> codec.decode(delegate) }
  11.  
  12. "/$department/"{
  13. controller = "home"
  14. action = "index"
  15. constraints {
  16. department(inList:['women','damen','γυναίκες'.encodeAsURL()])
  17. }
  18. }
  19.  
  20.  
  21. }
  22.  
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.