• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

internationalization  RSS feed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,

I am in the process internationalising my Struts application. In my application some of the messages to the user comes from java classes. I have hardcoded the messages. Can any one please tell me how to access keys from ApplicationResources.properties file in my java classes?


Any kind of help or hint is very much appreciated.

Thanks in advance.



Pavana Sree V
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Apache Struts class : MessageResources
 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Thanks for the reply. I am trying to use PropertyMessageResources class which is a subclass of MessageResources, but no success. Probably i am not using it properly. Code is as follows:


PropertyMessageResources pmr = (PropertyMessageResources)
PropertyMessageResources.getMessageResources("ApplicationResources");

String r=pmr.getMessage("int.back");

Application Resources is the name of the properties file.

It is not giving any error but returning null value.

Please let me know how to use it properly.


Thanks in advance.
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the action class' perform/execute method you call access application messages specified in the resources file by doing the following:
MessageResources resources = getResources();

You can then retrieve your message,
String message = resources.getMessage("int.back");

Sheldon Fernandes
 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Thanks for the solution. It worked out. But It says it is a deprecated. And I also have another issue regarding application resources.

I want to get the value of submit button from the application resources.

The following is giving me error:

<html:submit value="<bean:message key="int.add" />" />
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But It says it is a deprecated.


Try avoid using deprecated methods becos they might not be supported in the next release, and your code might need to be revised.


I want to get the value of submit button from the application resources.

The following is giving me error:

<html:submit value="<bean:message key="int.add" />" />


For the issue of reading values of HTML components via properties files, why dont you consider making use of Tiles, instead of using application resources?

Nick
 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Thanks for the reply.

As my application application is almost completed i can't go for tiles at this stage.

Can you please suggest me some other way to access application resources in html tags especially assigning values to the buttons?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In such case, the simply way is, as the controller knows how to prepare a view bean, you can let it read those values from the property file, and then put into the request scope. Thus, in your JSP, you can get the value of the button via the key in the scope.

It is a bit inconvenience, but it seems the fastest way you could do.

Nick
 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

thanks

Can you please give me some example?
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try to install some of the sample applications that come with struts. They supply all answers to your questions.
cheers,
friso
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can you please give me some example?



You can make use of the ResouceBundle to load the values:


Nick
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by pavanasree vasireddy:
hi,

Thanks for the reply. I am trying to use PropertyMessageResources class which is a subclass of MessageResources, but no success. Probably i am not using it properly. Code is as follows:


PropertyMessageResources pmr = (PropertyMessageResources)
PropertyMessageResources.getMessageResources("ApplicationResources");

String r=pmr.getMessage("int.back");

Application Resources is the name of the properties file.

It is not giving any error but returning null value.

Please let me know how to use it properly.


Thanks in advance.





ํYou must fixed your code like this ::



This will help you.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, you might need a class to wrap the access of ResouceBundle, because in case you cannot obtain the instance of the ResouceBundle, you will encounter NullPointerException.

In such case, in fact, I believe, if there are any problems, you will simply return the key, instead of throwing any exceptions, isnt it?

Nick
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!