Details
Description
JSP/Servlet specs have something like HttpServletResponse.encodeURL() or <c:url/> for url rewriting when cookies are disallowed on client side, in order to make sessions tracking still possible. Although (perhaps) more and more applications decide not to support that, it is still nice to have it; and it shouldn't be diffcult to achieve. Grails has excellent support of taglibs and currently (0.3.1) ApplicationTagLib.groovy is shipped with the release and copied to all grails apps created by 'grails create-app' in ./grails-app/taglib/. Basically I think a small change in ApplicationTagLib.groovy should solve it, specifically for these 3 tags, <g:link/>, <g:createLink/> and <g:createLinkTo/>. something like,
def createLinkTo = { attrs ->
// out << grailsAttributes.getApplicationUri(request)
// if(attrs['dir']) {
// out << "/$
// }
// if(attrs['file']) {
// out << "/${attrs['file']}"
// }
def u = ""
u += grailsAttributes.getApplicationUri(request)
if(attrs['dir']) {
u += "/${attrs['dir']}
"
}
if(attrs['file']) {
u += "/$
"
}
out << response.encodeURL(u)
}
I know it's very java
but it shows the idea and by using response.encodeURL() it is still standard-compliant and shouldn't have any side effect if cookies are enabled (which is the case for most end users). cheers!
also index.jsp in every grails created app ./web-app/ should be changed to use <c:url/> instead of <c:out/> to enable url rewriting in case cookies are disabled.
of course it's eventually down to individual developers to decide if they want to support url rewriting. but it would be nice to provide convenient methods to make it happen.