• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

:) :) :)
 
reply
    Bookmark Topic Watch Topic
  • New Topic