Take the 2-minute tour ×

I've been searching the net but couldn't find a solution for this. I need help on how to store my application specific configuration parameters into a flat text file or xml file. Is there a java package or class that provides this service?

For example configuration for datatable pagination length, etc. So I don't have to recompile my application whenever I need to change the pagination parameters.

Something like this: Maybe myApp.cfg file which contain this. pagination: 10,20,30,50

And then in my xhtml file I would have something like this.

<p:dataTable id="dtClientList" value="#{saClientController.lazyModel}" rowsPerPageTemplate="#{myApp.cfg.pagination}">

And maybe even access the configuration parameter from within my session scoped or application scoped backing bean. Then reuse them for multiple users.

Is it possible to user resource bundle properties file to store configuration parameters such as pagination length and access the parameters into backing bean like this?

  FacesContext fc = FacesContext.getCurrentInstance();
    ResourceBundle bundle = fc.getApplication().getResourceBundle(fc,"bundle_name");

Im searching for something similar to app.config file in dot net implementation which is XML.

Please help. And if my question does not make sense, do let me know. Big Thank You.

share|improve this question
The best thing for you to do will be creating an application scope object to store this value and provide an admin interface to manipulate it. This way you can avoid having to read a properties file everytime. If you still need a file based configuration, you can go for creating a properties file somewhere, either in the classpath or user home and read it for required values –  prajeesh kumar Mar 5 '12 at 8:26
Thanks @prajeesh kumar, is there a java class that can iterate and read each configuration keys easily? –  frazkok Mar 5 '12 at 8:40
Create the properties file like <key=<value> and load it into Properties like this Properties props = new Properties(); InputStream in = this.getClass().getResourceAsStream("myapp.properties"); props.load(in); And then from it you can get value for key like a map like String rowsStr=props.get("paging_rows"); –  prajeesh kumar Mar 5 '12 at 9:01

1 Answer 1

up vote 1 down vote accepted

You can use a properties file (simple text file) with content like this:

key1 = value1
key2 = value2

Name this file for instance MyResources.properties and put it in your source path root.

Then you can access a property file with the ResourceBundle class:

import java.util.ResourceBundle;
ResourceBundle rb = ResourceBundle.getBundle("MyResources");
String myValue1 = rb.getString("key1");

You can access this file from any session scoped bean you like. If the parameters are session independent, you could also use an application scoped bean instead.

share|improve this answer
I put it into constructor of my applicationscoped bean and get thrown unsafe operation exception. Any idea? –  frazkok Mar 5 '12 at 9:46
Where exactly is the exception thrown? –  Matt Handy Mar 5 '12 at 12:02
Hi @Matt Handy, nevermind I made a mistake. I did it like this FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "appconfig"); rowsPerPageTemplate = bundle.getString("rowsperpagetemplate"); –  frazkok Mar 6 '12 at 3:59

Your Answer


