resourcebundle

How to load a resource bundle from a file resource in Java?

做~自己de王妃 提交于 2019-11-26 12:26:09
问题 I have a file called mybundle.txt in c:/temp - c:/temp/mybundle.txt How do I load this file into a java.util.ResourceBundle ? The file is a valid resource bundle. This does not seem to work: java.net.URL resourceURL = null; String path = \"c:/temp/mybundle.txt\"; java.io.File fl = new java.io.File(path); try { resourceURL = fl.toURI().toURL(); } catch (MalformedURLException e) { } URLClassLoader urlLoader = new URLClassLoader(new java.net.URL[]{resourceURL}); java.util.ResourceBundle bundle =

String concatenation in EL for dynamic ResourceBundle key

不问归期 提交于 2019-11-26 09:40:01
问题 I have a resource bundle with entries like these: entry1=value1 entry2=value2 entry3=value3 In my JSF page I\'m trying to use these keys dynamically. The ID of the entry is coming from a managed bean. I think it should be something like this: <h:outputText value=\"#{msg[\'entry\' managedBean.entryIndex]}\"/> How can I achieve this? 回答1: If you're already on Servlet 3.1 / EL 3.0 (Tomcat 8, WildFly 8, GlassFish 4, etc), make use of new EL 3.0 += operator: <h:outputText value="#{msg['entry' +=

internationalization in JSF with ResourceBundle entries which are loaded from database

那年仲夏 提交于 2019-11-26 06:39:01
问题 I\'m working on a Java EE6 project using JPA/EJB/JSF and I\'m having some trouble designing multiple language support for entities. There are three relevant entities: Language (has id) Competence (has id) CompetenceName (has Competence reference, Language reference and a String) Competence has a one-to-many reference to CompetenceName implemented with a Map, containing one object for every Language that there exists a name for a Competence. Note that competences are created dynamically and

How to use UTF-8 in resource properties with ResourceBundle

本秂侑毒 提交于 2019-11-25 22:33:05
问题 I need to use UTF-8 in my resource properties using Java\'s ResourceBundle . When I enter the text directly into the properties file, it displays as mojibake. My app runs on Google App Engine. Can anyone give me an example? I can\'t get this work. 回答1: The ResourceBundle#getBundle() uses under the covers PropertyResourceBundle when a .properties file is specified. This in turn uses by default Properties#load(InputStream) to load those properties files. As per the javadoc, they are by default