Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSF
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
JSF
language propertis to xml properties
bostian tov
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Now i am using plain text language properties, but have some more complex stuff and want to start using xml.
Settings:
<application> <resource-bundle> <base-name>language.lng</base-name> <var>lng</var> </resource-bundle> <message-bundle>language.lng</message-bundle> <locale-config> <default-locale>en_US</default-locale> <supported-locale>sl_SI</supported-locale> </locale-config> </application>
Call from
jsf
:
<h:outputText value="#{lng.subscription}" />
Example:
subscription=Subscription
So how can i use xml file instead text file and what do i have to change? Thanks
Adrian Mitev
Greenhorn
Posts: 10
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In
java
1.6 you can use xml for properties files but the format is quite ugly.
Here
is an example of this.
bostian tov
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How can you access xml properties file from JFS(
jsp
) page? Now i am just refering to #{lng.someValue}
Adrian Mitev
Greenhorn
Posts: 10
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The same way as .properties files.
bostian tov
Ranch Hand
Posts: 32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
My code:
ResourceBundle rb = ResourceBundle.getBundle("lng", new ResourceBundle.Control() { public List<String> getFormats(String baseName) { if (baseName == null) throw new NullPointerException(); return Arrays.asList("xml"); } public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { if (baseName == null || locale == null || format == null || loader == null) throw new NullPointerException(); ResourceBundle bundle = null; if (format.equals("xml")) { String bundleName = toBundleName(baseName, locale); String resourceName = toResourceName("language/"+bundleName, format); InputStream stream = null; if (reload) { URL url = loader.getResource(resourceName); if (url != null) { URLConnection connection = url.openConnection(); if (connection != null) { // Disable caches to get fresh data for // reloading. connection.setUseCaches(false); stream = connection.getInputStream(); } } } else { stream = loader.getResourceAsStream(resourceName); } if (stream != null) { BufferedInputStream bis = new BufferedInputStream(stream); bundle = new XMLResourceBundle(bis, locale.getLanguage()+"_"+ locale.getCountry()); bis.close(); } } return bundle; } });
So on startup data for locale sl_SI is beeing loaded. So do i need to have this code or should i change it somehow to get this working?
<application> <resource-bundle> <base-name>language.lng</base-name> <var>lng</var> </resource-bundle> <message-bundle>language.lng</message-bundle> <locale-config> <default-locale>sl_SI</default-locale> </locale-config> </application>
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Override request headers
locales and jsf
java.util.MissingResourceException
Resource bundle in Prime faces
Using custom resourceBundle that accepts UTF-8: can't find bundle for base name
More...