Paul Waldo
Paul Waldo

Reputation: 1233

Unable to load CSS using grails rendering plugin

I have a grails 2.4.3 app that uses the rendering 1.0.0 plugin and asset-pipeline:1.9.9. I can successfully generate a PDF from a GSP, but

When I comment out all CSS references, there are no errors, but it still looks like garbage. I believe the stream closed problem is due to the XHTML parser not being able to load the CSS file. The CSS references look like this

<link rel="stylesheet" href="/Invoicer/assets/invoicer.css?compile=false"  />

When I load up that URL in the browser, the CSS file is successfully returned and displayed.

I'm also using Spring Security and thought that maybe it was an authentication issue. I removed all of the filters in Config.groovy, so it looks like this

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
    '/**':                          ['permitAll']
]

but that did not help. Any ideas? Thanks!

Upvotes: 2

Views: 620

Answers (2)

Paul Waldo
Paul Waldo

Reputation: 1233

After re-reading the documentation, I noticed this:

The rendering engine resolves all relative links relative to the grails.serverURL config property.

I figured serverURL would have been set automatically, but it wasn't. I set

grails.serverURL = "http://localhost:9090/${appName}"

in Config.groovy as well as

grails.server.port.http = 9090

in BuildConfig.groovy. It also appears that they layout engine is not getting called, so I had to manually pull in the CSS files:

<asset:stylesheet src="invoicer.css" />

Upvotes: 2

Paul Waldo
Paul Waldo

Reputation: 1233

Here is an answer, but it's ugly. I noticed that specifying the full path to the CSS indeed did work:

<link rel="stylesheet" href="http://localhost:9090/Invoicer/assets/bootstrap.css?compile=false" />

Now, since I'm using asset-pipeline, I have to make asset-pipeline use an absolute URL in Config.groovy:

grails.assets.url = "http://localhost:9090/Invoicer/assets/"

Not pretty, but it will work for now.

Upvotes: 0

Related Questions