Search code examples
grailsgsp

Nesting quotes: a message tag inside a javascript fragment inside of an actionsubmit tag


I have a submit button where I want a confirmation pop-up, doing this works fine:

<g:actionSubmit value="Delete" 
action="deleteTpsReport" 
onclick="return confirm('ohnoes!');"

But when I want to move the confirmation text into the messages.properties file I try:

<g:actionSubmit value="Delete" 
action="deleteTpsReport" 
onclick="return confirm('<g:message code="tps.delete.confirmation"/>');"

which doesn't work, the ');" gets displayed on the page and the javascript is totally ignored.

Is there a way to nest these tags so that I can use message in the event handler of the actionSubmit?


Solution

  • This should work:

    <g:actionSubmit value="Delete" 
    action="deleteTpsReport" 
    onclick="return confirm('${message(code: 'tps.delete.confirmation')}');"/>