Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was unable to solve this problem in terms of OOP. I mean I can't find way how to override closure. I tried several approaches, but with no success. And documentation <a href="http://groovy.codehaus.org/Closures+-+Formal+Definition" rel="nofollow">says</a> that you can't override closure, you can only replace it with new implementation (please correct me if I wrong).</p> <p><strong>But (!)</strong> I was able to solve task by copy-pasting source code of ApplicationTagLib#createLink method. I think this is brutal solution, but after 8 hours of fighting with this simple task - it's acceptable.</p> <p>So finally all I need to do - is define this class, grails will immediately use it for link generation (for all views, no need to change their code):</p> <pre><code>import java.text.SimpleDateFormat; import groovy.time.*; import java.text.*; import org.codehaus.groovy.grails.commons.GrailsControllerClass import org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib; import org.codehaus.groovy.grails.web.mapping.UrlCreator import org.codehaus.groovy.grails.commons.ControllerArtefactHandler import org.springframework.web.context.request.RequestContextHolder class OverrideTagLib extends ApplicationTagLib { def createLink = { attrs -&gt; // get value for regionId parameter def regionId = regionIdFinderService.currentRegionId // add cutsom regionId parameter if (attrs) { if (attrs.params) attrs.params.put("regionId", regionId); else { attrs.params = ["regionId":regionId]; } } // process def writer = getOut() // prefer URI attribute if (attrs.uri) { writer &lt;&lt; handleAbsolute(attrs) writer &lt;&lt; attrs.uri.toString() } else { // prefer a URL attribute def urlAttrs = attrs if (attrs.url instanceof Map) { urlAttrs = attrs.remove('url').clone() } else if (attrs.url) { urlAttrs = attrs.remove('url').toString() } if (urlAttrs instanceof String) { if (useJsessionId) { writer &lt;&lt; response.encodeURL(urlAttrs) } else { writer &lt;&lt; urlAttrs } } else { def controller = urlAttrs.containsKey("controller") ? urlAttrs.remove("controller")?.toString() : controllerName def action = urlAttrs.remove("action")?.toString() if (controller &amp;&amp; !action) { GrailsControllerClass controllerClass = grailsApplication.getArtefactByLogicalPropertyName(ControllerArtefactHandler.TYPE, controller) String defaultAction = controllerClass?.getDefaultAction() if (controllerClass?.hasProperty(defaultAction)) { action = defaultAction } } def id = urlAttrs.remove("id") def frag = urlAttrs.remove('fragment')?.toString() def params = urlAttrs.params &amp;&amp; urlAttrs.params instanceof Map ? urlAttrs.remove('params') : [:] def mappingName = urlAttrs.remove('mapping') if (mappingName != null) { params.mappingName = mappingName } if (request['flowExecutionKey']) { params."execution" = request['flowExecutionKey'] } if (urlAttrs.event) { params."_eventId" = urlAttrs.remove('event') } def url if (id != null) params.id = id def urlMappings = applicationContext.getBean("grailsUrlMappingsHolder") UrlCreator mapping = urlMappings.getReverseMapping(controller,action,params) // cannot use jsessionid with absolute links if (useJsessionId &amp;&amp; !attrs.absolute) { url = mapping.createURL(controller, action, params, request.characterEncoding, frag) def base = attrs.remove('base') if (base) writer &lt;&lt; base writer &lt;&lt; response.encodeURL(url) } else { url = mapping.createRelativeURL(controller, action, params, request.characterEncoding, frag) writer &lt;&lt; handleAbsolute(attrs) writer &lt;&lt; url } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload