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

Alerts

 
Arulanand Dayalan
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.
 
Purushoth Thambu
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.
 
Merrill Higginson
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic