Reputation: 851
I have a text in gsp as follows:
<g:message code="${code}" locale="${locale}"/>
The problem is the message returned can contain characters such as &
and when exporting this gsp to pdf, the following error occurs:
Caused by: org.xml.sax.SAXParseException; lineNumber: 396; columnNumber: 44; The entity name must immediately follow the '&' in the entity reference.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
This issue could be resolved if &
could be replaced by &
I have tried using g:encodeAs
but that didn't help. I cannot change the &
in messages.properties to &
or and
.
Is it even possible to replace a text returned from messages.properties before rendering in gsp?
Upvotes: 2
Views: 182
Reputation: 851
I solved the problem using the following code:
${JsonUtil.parseTextForXhtml(message(code:code, locale: locale))}
And then in JsonUtil, I replaced &
with &
as follows:
static String parseTextForXhtml(String text) {
text.replaceAll("&", "&")
}
Upvotes: 1