I manage two properties is one for the generic messages and one for each module belonging to my system, but the problem I'm having is that when invoking the first method getMessage() always invokes the properties of the resource, when it should go the message.
public class ResourceBundleUtil implements Serializable {
private static final long serialVersionUID = 1L;
public static final String MESSAGE_PATH = "messages";
public static final String RESOURCE_PATH = "resources";
private static HashMap<String, Object> messageBundles = new HashMap<String, Object>();
public static String getMessage(String key) {
if (key == null) {
return null;
}
try {
Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
if (locale == null) {
locale = Locale.ENGLISH;
}
ResourceBundle messages = (ResourceBundle) messageBundles.get(locale.toString());
if (messages == null) {
messages = ResourceBundle.getBundle(MESSAGE_PATH, locale);
messageBundles.put(locale.toString(), messages);
}
return messages.getString(key);
} catch (Exception e) {
return key;
}
}
public static String getResource(String key) {
if (key == null) {
return null;
}
try {
Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
if (locale == null) {
locale = Locale.ENGLISH;
}
ResourceBundle messages = (ResourceBundle) messageBundles.get(locale.toString());
if (messages == null) {
messages = ResourceBundle.getBundle(RESOURCE_PATH, locale);
messageBundles.put(locale.toString(), messages);
}
return messages.getString(key);
} catch (Exception e) {
return key;
}
}
}
The problem I have is that the getMessage() method always invokes the resource propertie, when should the message:
if (messages == null) {
messages = ResourceBundle.getBundle(MESSAGE_PATH, locale);
messageBundles.put(locale.toString(), messages);
}
No enters the conditional, and noticed that comes with name value is resource.
Unlike the method getResource() if I notice that operating normally.
Please I could comment on that problem should, thanks.