Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Alerts

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am using struts application. I had all Field Names configured in an message-resources file. So i can support internationalizaion. My problem i show all the error messages in an Javascript alert box. For example front end validations at client side. Since i cant access the message resources in javascript i am hardcoding it. So, is there anyway out so that i can change the alert messages in javascript based on locale.

Thanks in advance.

Regards,
Arul.
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just can't do that in Javascript (unless you use Ajax and request messages from the server). Once the HTML Response is flushed to the client you can't have javascript access the resource bundle (Javascript is meant for client side & resource bundles are at server side). . Here is how you can solve this issue.
- Have Javascript generated through JSP. You populate the messages from resource bundle into a javascript array through JSP.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Struts validation framework client-side validation solves this problem by generating the JavaScript code dynamically at runtime. That way the message keys are evaluated to the locale of the current user.

You may want to look into using the Struts Validation Framework for your validation.
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merrill,
Is there a URL which explains about the client-side validation. I didn't pay too much attention after seeing that javascript are embedded at using CDATA section. I am looking for sort of simple example. Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Purushothaman,

Sorry it took me a while to respond. This thread kind of got lost in the shuffle.

In answer to your question, this link has a good, simple example of Struts client-side validation.
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill, I will take a look, haven't tried client side validation till this day.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic