aspose file tools*
The moose likes Struts and the fly likes Displaying javascript alerts by reading from ApplicationResources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying javascript alerts by reading from ApplicationResources" Watch "Displaying javascript alerts by reading from ApplicationResources" New topic
Author

Displaying javascript alerts by reading from ApplicationResources

Varsha Patil
Greenhorn

Joined: Jun 16, 2006
Posts: 19
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

Joined: Sep 22, 2006
Posts: 25
Hi
try to do it . hope it will solve problem.

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

i think it will work...


ACHALVEER SINGH<br />SOFTWARE ENGINEER
Varsha Patil
Greenhorn

Joined: Jun 16, 2006
Posts: 19
It works. Thanks!
Varsha Patil
Greenhorn

Joined: Jun 16, 2006
Posts: 19
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

Joined: Feb 03, 2004
Posts: 456
because jsp-code is not evaluted in js-files :-)
Varsha Patil
Greenhorn

Joined: Jun 16, 2006
Posts: 19
That explains it. Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
thanks merrill, i did not think that far...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Displaying javascript alerts by reading from ApplicationResources