resourcebundle

Pass parameters to messages from resource bundle to components other than **h:outputFormat**

只谈情不闲聊 提交于 2019-11-27 18:04:31
问题 Is there a convenient way to pass parameters to messages from resource bundle to components other than h:outputFormat ? For instance, this is legal: <h:outputFormat value="#{myBundle['parametricMessage']}"> <f:param value="#{myBundle['someParameterValue']}"/> </h:outputFormat> But I need it for a button, like this (which won't work): <h:commandButton value="#{myBundle['parametricMessage']}"> <f:param value="#{myBundle['someParameterValue']}"/> </h:commandButton> Of course, I can use link

How do I specify values in a properties file so they can be retrieved using ResourceBundle#getStringArray?

佐手、 提交于 2019-11-27 13:55:06
I am trying to use ResourceBundle#getStringArray to retrieve a String[] from a properties file. The description of this method in the documentation reads: Gets a string array for the given key from this resource bundle or one of its parents. However, I have attempted to store the values in the properties file as multiple individual key/value pairs: key=value1 key=value2 key=value3 and as a comma-delimited list: key=value1,value2,value3 but neither of these is retrievable using ResourceBundle#getStringArray . How do you represent a set of key/value pairs in a properties file such that they can

ResourceBundle not found for MessageSource when placed inside a folder

我是研究僧i 提交于 2019-11-27 12:29:57
问题 I am trying to use resource bundles with Spring's Message Source. Here is the way I am doing it: @Component public class MessageResolver implements MessageSourceAware { @Autowired private MessageSource messageSource; public void setMessageSource(MessageSource messageSource) { this.messageSource = messageSource; } public String getMessage(){ return messageSource.getMessage("user.welcome", new Object[]{"Rama"} , Locale.US); } } And here is my folder structure: messages_en_US.properties contains

Format a message using MessageFormat.format() in Java

拟墨画扇 提交于 2019-11-27 10:25:24
问题 I have stored some messages in a resource bundle. I'm trying to format these messages as follows. import java.text.MessageFormat; String text = MessageFormat.format("You're about to delete {0} rows.", 5); System.out.println(text); Assume that the first parameter i.e the actual message is stored in a property file which is somehow retrieved. The second parameter i.e 5 is a dynamic value and should be placed in the placeholder {0} which doesn't happen. The next line prints, Youre about to

Injecting ResourceBundle via @ManagedProperty doesn't seem to work inside @Named

你说的曾经没有我的故事 提交于 2019-11-27 07:14:30
问题 How can I access messages bundle from java code to get message according to current locale? I tried using @ManagedProperty like below: @Named @SessionScoped public class UserBean implements Serializable { @ManagedProperty("#{msg}") private ResourceBundle bundle; // ... public void setBundle(ResourceBundle bundle) { this.bundle = bundle; } } However, it remains null . It seems that it doesn't work inside a @Named . This is how I registered the resource bundle in faces-context.xml :

java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US

十年热恋 提交于 2019-11-27 02:30:25
问题 I am trying to create a utility class ReadPropertyUtil.java for reading data from property file. While my class is located under a util directory , my skyscrapper.properties file is placed in some other directory. But , when i try to access the properties using [ResourceBundle][1] , i get exceptions, that bundle can't be loaded. Below is the code on how I am reading the properties and also an image which shows my directory structure. ReadPropertiesUtil.java /** * Properties file name. */

MVC bundle client caching

落爺英雄遲暮 提交于 2019-11-27 01:51:16
问题 By default a MVC bundle is cached on client for 1 year. Is it possible to set it's client headers manually (for 1 specific bundle)? What I need is to set custom expire headers for one of my bundles. I can't rely on the "v=hash" querystring because this bundle is for an external website, and they won't change the url pointing to my bundle each time I change it. What I've tried is to create a custom Bundle class (inherit Bundle) and overridde the GenerateBundleResponse() method. This way I can

String concatenation in EL for dynamic ResourceBundle key

混江龙づ霸主 提交于 2019-11-27 01:27:39
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? 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' += managedBean.entryIndex]}" /> If you're only on Servlet 3.0 / EL 2.2 (Tomcat 7, JBoss AS 6/7, GlassFish 3, etc),

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

社会主义新天地 提交于 2019-11-27 01:06:59
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 = java.util.ResourceBundle.getBundle( path , java.util.Locale.getDefault(), urlLoader ); As long as you

internationalization in JSF with ResourceBundle entries which are loaded from database

[亡魂溺海] 提交于 2019-11-26 20:25:22
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 their names can thus not exist in a resource bundle. When listing the Competences on a web page, I want