Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ResourceBundles in an MVC environment

 
Ranch Hand
Posts: 173
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best ranchers!

I have just begun to implement the MVC design pattern in my projects. All of theese projects supports internationalization and I use ResourceBundles to meet that technique. Now my question is how I should handle theese bundles in an MVC environment? How do they do this in a real world application? I understand the basics so far conserning model, view and controller classes, but I am lost when it comes to internationalization and handling resource bundles. Do the requests to a bundle belong in a Model or a Controller-class and how would it look like in a code sample? Many thanks in advance and thank you for reading!

Best wishes,
Robert!
 
Saloon Keeper
Posts: 22254
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically you'd load the resources into a Java Properties object. You then work with that object in the usual way.

For web applications, references to resources would typically be made to a read-only Model object. So on platforms such as JavaServer Faces, you'd use EL on the View Template in something like this:


You have to be a little more creative if you want the language and other I18N information to be served on a per-user basis, but nothing that hasn't been done many times before.
 
Robert Ingmarsson
Ranch Hand
Posts: 173
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply!

I see. I have used jsp and servlets before when speaking of web applications - not using jsf however. I am writing standalone applications using swing components though. But I see the point. My first assumption is to create a LanguageController class in which I load the proper locale for the currently selected ResourceBundle when the user hits the different menu items that represents a language, in my menubar. But I don't know how such an operation works in an MVC-wise manner.

Could a demonstration be possible?

 
Tim Holloway
Saloon Keeper
Posts: 22254
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In basic JSP/servlets, you'd do the same thing. You'd have a resource backing bean in Application or Session scope (session scope for per-user I18N). You'd still use EL on the View Template (JSP). I think you'd need a useBean tag to make it visible, though. So something like this:


Note that the "#" and "$" notations differ only in that "$" denotes a read-only property value whereas "#" is a property reference used for read/write. JSF, however, normally uses "#" regardless because of historical reasons and because "#" is a superset of "$" anyway.

I haven't done Swing in a while, but the concepts are similar except that since Swing doesn't have a templating facility you have to do it all in code. Android, of course, does that sort of stuff routinely so virtually any Android app will have been set up that way from the beginning.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this 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