Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

There are some messages coming from a Javascript file to a GSP page. How can I implement g:message in a Javascript page?

For example:

if ($('#name').val() == "") {
    $('#nameStatus').show();
    $('#nameStatus').html('<font color=red>Company Name can not be blank</font>');
    return false;
share|improve this question
add comment (requires an account with 50 reputation)

2 Answers

If I understand correctly, you want to be able to use the output from g:message in your javascript.

There is a very helpful blog post which talks about how to use g:createLink in a similar way that you want, so you can easily adapt it to use g:message as well. Check out the post here, there is some useful info in the comments as well.

The idea is to create javascript objects in your GSP file; which should be defined before including your javascript file; and then just access those global objects in your js code.

Edit:

You might also be interested in the GSParse Plugin. I haven't tried it my self but I think it accomplishes what you are looking for as well.

share|improve this answer
add comment (requires an account with 50 reputation)

Try this kind of syntax :

function foo() {
    return "${message(code:'my.message.code')}";
}
share|improve this answer
That would work if your javascript is within your GSP file, but if you are including a .js file it won't work afaik – omarello Nov 28 '11 at 17:11
That's right... :-p – Philippe Nov 28 '11 at 21:13
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.