Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call message resource bundle(language properties file) through javascript on JSP?

 
Vinod Vijay
Ranch Hand
Posts: 150
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a language properties file(message resource file). I'm trying to call keys defined in that file in javascript function by using javascript alert() on JSP but it is not coming up.

Code:-


It is just alerting like ???iqNumberFormatCheck???. Exact message is not coming up.
 
Paul Clapham
Sheriff
Posts: 21124
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do that. The "fmt:message" tag is evaluated on the server as part of the JSP processing which produces the HTML. The Javascript is executed much later, on a different computer, in a different environment (the browser) which doesn't have any access to the resource bundle.

However perhaps evaluating that expression on the server is actually what you want. Is the string "iqNumberFormatCheck" actually a key to the resource bundle? If so then perhaps the problem is just that you didn't use the fmt:message tag correctly, e.g. by not specifying the resource bundle correctly.
 
Vinod Vijay
Ranch Hand
Posts: 150
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You can't do that. The "fmt:message" tag is evaluated on the server as part of the JSP processing which produces the HTML. The Javascript is executed much later, on a different computer, in a different environment (the browser) which doesn't have any access to the resource bundle.

However perhaps evaluating that expression on the server is actually what you want. Is the string "iqNumberFormatCheck" actually a key to the resource bundle? If so then perhaps the problem is just that you didn't use the fmt:message tag correctly, e.g. by not specifying the resource bundle correctly.


Thanks! I have resolved the issue by myself. I was missing to specify the message bundle first. I used fmt:setBundle and specifed my message resource file. Now it is working fine.
@Paul - 'iqNumberFormatCheck' is the actual key in property file.

:) :) :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic