Wednesday, May 2, 2012

Using rendering plugin in Grails

I use the grails rendering plugin to create PDF versions of pages. It is a very useful plugin, unfortunately I've encountered an error with tags containing the id attribute, the problem is reported as:

org.w3c.dom.DOMException: NOT_FOUND_ERR: An attempt is made to reference a node in a context where it does not exist .

Why this happen? I don't know but thankfully I found this post about the same problem. As it is stated in the post one can resolve the problem by using the system property xr.load.configure-features=true, but it does not say where it can be placed within the code or if it is a configuration parameter of the application.

According to the documentation of flying saucer (the underlying implementation of rendering), specifically the class Configuration.java, one can define the configuration parameters via a properties file defined by the system property xr-conf or directly redefining the xr.* variable in the command line using the argument -Dxr.*=param.

But in grails that wouldn't be appropiated because the code base is shared and everyone with access to the code would need to define the variable.

Fortunately grails provides a simple way to add system properties programmatically at application startup. This can be done in the Bootstrap.groovy file, in this case the line to make the rendering plugin would be: System.setProperty("xr.load.configure-features", "true").

So to make simple, in order to use the rendering plugin with tags with id attributes use System.setProperty("xr.load.configure-features", "true") in Bootstrap.groovy.

No comments:

Post a Comment