tags:

views:

200

answers:

2

In my Grails GSP file I'm using the HTML meta tag:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

The problem is that Grails closes this tag and renders it as:

<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>

This fails W3C's HTML validation (since my doctype is HTML and not XHTML). Is there a fix for this? How can I get Grails to not interpret the meta tag?

I'm using grails-1.2-M4.

Follow up: I create the Grails bug GRAILS-5696 for this issue.

+2  A: 

Not sure that this is the most beautiful solution, but at least it will work for your case:

<%= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' %>

Well...this does not work since it is preprocessed by Grails before displayed as is.

So the only solution I see is to create a TagLib and output the content like this:

class MetaTagLib {

    static namespace = 'my'

    def meta = {
        out << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"
    }
}

and use it like:

<my:meta />

It works. Tested.

fabien7474
Unfortunately it doesn't work and results in <sitemesh:captureMeta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
Steve Kuo
See my updated answer.
fabien7474
Yes it works. I'm going to file this as a Grails bug. I should be able to produce 100% valid HTML using Grails.
Steve Kuo
A: 

You could validate as HTML5 instead of HTML 4.01, by using <!DOCTYPE html> (that's it, really!). HTML5 allows trailing slashes even in the HTML syntax, in order to allow for systems like this that produce pseudo-XHTML.

Of course, HTML5 is not yet a finished standard; it may change. I think that this aspect of it is unlikely to be changed, but there is still some fairly contentious debate about a lot of the new HTML5 features, so keep in mind that it's not yet finalized.

Brian Campbell