The moose likes JSF and the fly likes How to access the property file from Java code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to access the property file from Java code?" Watch "How to access the property file from Java code?" New topic

How to access the property file from Java code?

Fabricio Zelada

Joined: Dec 28, 2011
Posts: 7

Im using JSF+primefaces, and I have a property file regex.property that contain some string I wanna use from the Java code (server side). I know I can open the file and read it; but I also know that those files are already bundled (since they are declared in faces-config file). Does someone can tell me, how can access this resource? or how to find it?


Vladimir Mokrozub

Joined: Aug 31, 2012
Posts: 12

Also, since ResourceBundle is part of standard JDK, you don't need to bundle your property file in faces-config.xml
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951

If I'm not mistaken, when you define a resource bundle in faces-config, you assign a bean name to it.

While its most common use is as an anchor for JSF View resources such as messages and labels, I'm fairly certain that you could also inject this bean as a managed property into a JSF backing bean and do a standard resource lookup on it.

The main advantage of that approach is that since it's done via Inversion of Control, you don't have to hard-code the resource location in your backing bean.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link: http://aspose.com/file-tools
subject: How to access the property file from Java code?
Similar Threads
Error Reading an xml file from a servlet
Hibernate connection close issue.
Property File Reload problem
How to use the Ant Property file setting?
Policy file question and readme question