alert('<bean:message key="MSG001"/>');
Validation Message:
var fieldname = '<bean:message key="fieldname.amount"/>';
var errorMsg = '<bean:message key=" errors.float" arg0="'+fieldname+'"/>';
alert(errorMsg);
In Message Resource:
MSG001 Hello world!
fieldname.amount Payment Amount
errors.float {0} is not a float
The code above merely prints out the literal text that is entered within the alert field. Is there some configuration change you’ve made to allow the alert to retrieve its value from the MessageResource?
Nope.. don’t remember having to change any configurations
Looks like adding the = between the key and value in the message resources causes a screw up. Separating them by a space and using it works fine.
That being said, the nested nature of the errorMsg example seems to be giving issues since the alert is rendering the errorMsg as a literal string instead of extracting both the arg0 and message from the MessageResources.
I am curious as to why the types of quotations used for fieldname is different from the types of quotations used for errorMsg.
struts syntax uses ” quotations to display a message from the message resource
<bean:message key="MSG001"/>javascript syntax to alert a string uses ‘ quotations
alert('');what we’re doing here is using the struts syntax to get the message we want into the javascript alert. Thats the reason for the different types of quotation
var errorMsg = '<bean:message key=" errors.float" arg0="'+fieldname+'"/>';the struts requests are always handled first before javascript which is why we can do this
I haven’t touched struts in a long time and am not sure why you’re getting the literal strings but this code worked in my previous project.
Hope I’ve helped a little bit
What if your message has both single and double quotes?