• SEARCH BOX

Combine Jetty and Spring Application Context

Spring's Logo The goal of this post is to use one xml configuration file which is Spring's applicationContext.xml and load it only once for the duration of the application running in an embedded jetty server. Read more...

Tutorial on Android Layout

A thumbnail of adroid. Android is an open source platform for mobile devices. Not a hardware. It is a software stack as defined by Google. Encase your not familiar with the term, software stack is compose of an Operating System(OS), middle-ware and the key applications. Read more...

Hi, my name's Paul Labis.

I'm a developer in Makati City, Philippines. Focused on building online Java/J2EE based applications. I'm interested in freelance or part-time work from home.

Saturday, May 29, 2010

Use Arguments on Property File

The goal on this tutorial is to be able to format a value on a properties file given its parameter or arguments. It is best describe as passing value as a parameter and inserting those values on the string retrieved from the properties file.

To better understand what I'm doing, read and understand my example code below.

Property File Sample
message.welcome= Welcome {0} to {1}!
message.thank= Thank you for you visit {0}.
Java Code using  ResourceBundle and MessageFormat
ResourceBundle resBundle = new ResourceBundle("path to property file");
String welcomeText=resBundle.getString("message.welcome");
MessageFormat msgFormatter = new MessageFormat(welcomeText);

// Create the dynamic args you want to replace
Object[] messageArguments = {"Techie boy","Philippines"}; 

String finalText= msgFormatter.format(messageArguments);

The finalText will result to "Welcome Techie boy to Philippines!"

0 comments :

Post a Comment

 

Author

Followers

Techie Projects

Open Source