Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying javascript alerts by reading from ApplicationResources

 
Varsha Patil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

For displaying alert messages in javascript function calls I need to read the text from ApplicationResources.properties file.
I have tried the following combinations but nothing seems to be working. The text message is not being read from the properties file. Can someone give me the correct syntax.

1. alert(<bean:message key="message.invalidName"/> ;

2. alert('<bean:message key="message.invalidName"/>');

3. alert(<bean:message key='message.invalidName'/>");

4. alert(<bean:message key=message.invalidName'/> ;
In ApplicationResources
message.invalidName=The given name is invalid

Thanks in Advance
 
Achalveer Singh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
try to do it . hope it will solve problem.

alert('<bean:message key="message.invalidName"/>');

i think it will work...
 
Varsha Patil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works. Thanks!
 
Varsha Patil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I include the javascript code in the jsp file it works. But if I move the javascript code to a separate js file and include that js file in the jsp then it does not work. I wonder why?
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because jsp-code is not evaluted in js-files :-)
 
Varsha Patil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That explains it. Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Jan says is true. However, if you do it like this:

<script type="text/javascript" src="myJavaScript.jsp></script>

It does work. This is assuming that myJavaScript.jsp contains javascript code with some JSP or Struts tags included.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks merrill, i did not think that far...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic