]> git.mxchange.org Git - jjobs-war.git/commitdiff
finally fixed this madness, thanks to @BalusC again:
authorRoland Häder <roland@mxchange.org>
Mon, 15 Aug 2016 09:27:15 +0000 (11:27 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 19 Aug 2016 21:07:47 +0000 (23:07 +0200)
- I wanted to have a general ("base") controller that hold methods for every controller (bean).
- like many controllers do, I want that bean to return localized message from my resource bundle and not unlocalized English-only messages
- this is now done by getting the container's locale and then loading the bundle with it's base name (not variable name)
- thank you, BalusC for enlighten us. :-)

src/java/org/mxchange/jjobs/beans/BaseJobsController.java

index d57534b76c89b355af79576a8013eee0de5918e3..de5289f47f88887857c4e31a6328a3473300a702 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.jjobs.beans;
 
 import java.io.Serializable;
 import java.text.MessageFormat;
+import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import javax.faces.application.FacesMessage;
@@ -131,23 +132,23 @@ public abstract class BaseJobsController implements Serializable {
                // Both parameter must be valid
                if (null == clientId) {
                        // Throw NPE
-                       throw new NullPointerException("clientId is null");
+                       throw new NullPointerException("clientId is null"); //NOI18N
                } else if (clientId.isEmpty()) {
                        // Is empty
-                       throw new IllegalArgumentException("clientId is null");
+                       throw new IllegalArgumentException("clientId is null"); //NOI18N
                } else if (null == i18nKey) {
                        // Throw NPE
-                       throw new NullPointerException("i18nKey is null");
+                       throw new NullPointerException("i18nKey is null"); //NOI18N
                } else if (i18nKey.isEmpty()) {
                        // Is empty
-                       throw new IllegalArgumentException("i18nKey is null");
+                       throw new IllegalArgumentException("i18nKey is null"); //NOI18N
                }
 
-               // Get facet context
-               FacesContext context = FacesContext.getCurrentInstance();
+               // Get current locale
+               Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
 
-               // Get bundle
-               ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg"); //NOI18N
+               // Get bundle bundle
+               ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale);
 
                // Default is i18nKey
                String message = i18nKey;
@@ -161,7 +162,7 @@ public abstract class BaseJobsController implements Serializable {
                }
 
                // Get context and add message
-               context.addMessage(clientId, new FacesMessage(message));
+               FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
        }
 
 }