Then why don't you just test if the String returned is the code itself?
<g:if test="${message(code: 'default.code.foo') == 'default.code.foo'}">
true
</g:if><g:else>
false
</g:else>
If you need to do this in several places and want to make the code a bit more concise, then put this logic in a tag lib.
class MsgTagLib {
static namespace = 'msg'
def messageSource
private static final NO_ARGS = [].toArray();
def exists = {attrs ->
try {
messageSource.getMessage(attrs.code, NO_ARGS, Locale.default)
out << true
} catch (NoSuchMessageException e) {
out << false
}
}
}
You could then call this in a GSP using:
<msg:exists code="default.code.foo"/>
Note
- The tag lib above is 100% untested, beware!
- The
exists
tag in it's form above doesn't support parameterized messages