Reputation: 7619
When I am using
<g:link url="https://www.google.co.in">Google 1</g:link>
this gives me correct result, a link to https://www.google.co.in.
Google 1
But when I am using
${g.link(url: "https://www.google.co.in") { 'Google 2' }}
this gives me
<a href="https://www.google.co.in">Google 2</a>
which is a text not a link.
I have tried encodeAsHTML()
and decodeHTML()
but result is same.
What I am doing wrong here? How I can get the link instead of text?
Using grails 2.3.7
and have grails.views.default.codec = "html"
in my Config file.
Upvotes: 1
Views: 353
Reputation: 4998
This information can be useful, it is from grails documentation
http://grails.org/doc/2.3.1/guide/security.html
Each tag library created has the opportunity to specify a default codec used to encode output from the tag library using the "defaultEncodeAs" property:
static defaultEncodeAs = 'html'
Encoding can also be specified on a per tag basis using "encodeAsForTags":
static encodeAsForTags = [tagName: 'raw']
Upvotes: 2
Reputation: 13075
You set grails.views.default.codec='html'
in Config.groovy
to get HTML escaping by default on all ${expressions}
in the application.
To disable HTML encoding for your gsp set <%@page defaultCodec="none" %>
in the top of your gsp.
Upvotes: 1
Reputation: 1096
You are probably seeing a security feature in grails: "Cross Site Scripting (XSS) Prevention"
In a nutshell, try (untested):
${raw(g.link(url: "https://www.google.co.in") { 'Google 2' })}
See http://grails.org/doc/latest/guide/security.html#xssPrevention for more. All of that section is worth reading 'cos there are several configuration options available.
Upvotes: 3