Search code examples
grailsgsp

Grails: Why is <g:link> not emitting links?


I have:

<td>
   <g:link controller="dashboard" action="view">Dashboard</g:link>
   <a href="fkd.co">Hello</a>
</td>

The result is:

Dashboard Hello


Solution

  • I just found out that <g:link> was overwritten and it was made only to create the links if the logged in user has access to that link otherwise emit the body text. The code looks like:

    def link = { attrs, body ->
    
            def url = "/${pageScope.controllerName}/${attrs.action}"
    
            if( !securityService.isLoggedIn() ||
                securityService?.hasAccessToUri("/${pageScope.controllerName}/${attrs.action}") ) {
    
                def originalTagBean = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
    
                originalTagBean.link.call(attrs, body)
            } else {
                out << body()
            }
    
        }