wood burning stoves 2.0*
The moose likes Struts and the fly likes Alerts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Alerts" Watch "Alerts" New topic
Author

Alerts

Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
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

Joined: May 24, 2003
Posts: 425
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

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


Merrill
Consultant, Sima Solutions
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
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

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

Joined: May 24, 2003
Posts: 425
Thanks Merrill, I will take a look, haven't tried client side validation till this day.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alerts
 
Similar Threads
internationalization for javascript in spring MVC
How to display French and German Character in Javascript Alert?
how to access values in session from javascript
re:To get alert messages like when we sign in google talk
Struts Validation Framework