import java.security.Principal;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
*/
public abstract class BaseFacesBean extends BaseBean {
+ /**
+ * Loaded resource bundles ("cached")
+ */
+ private static final List<ResourceBundle> RESOURCE_BUNDLES;
+
/**
* Serial number
*/
private static final long serialVersionUID = 18_605_498_672_261L;
+ /**
+ * Static initializer
+ */
+ static {
+ // Init resource bundle list
+ RESOURCE_BUNDLES = new ArrayList<>(2);
+ }
+
+ /**
+ * Getter for resource bundle list
+ * <p>
+ * @return Resource bundle list
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ protected static List<ResourceBundle> getBundles () {
+ return RESOURCE_BUNDLES;
+ }
+
/**
* Protected constructor
*/
final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
// Get bundle bundle
- final ResourceBundle bundle = this.loadResourceBundle(locale);
+ this.loadResourceBundles(locale);
// Default is i18nKey
String message = MessageFormat.format("???{0}???", i18nKey); //NOI18N
- // Try it
- try {
- // Get message
- message = bundle.getString(i18nKey);
- } catch (final MissingResourceException ex) {
- // Did not find it, ignored
+ // Loop through all
+ for (final ResourceBundle bundle : getBundles()) {
+ // Found message?
+ // Try it
+ try {
+ // Get message
+ message = bundle.getString(i18nKey);
+ break;
+ } catch (final MissingResourceException ex) {
+ // Did not find it, ignored
+ }
}
// Return it
}
/**
- * Loads resource bundle for given locale. This must be implemented per
+ * Loads resource bundles for given locale. This must be implemented per
* project so all projects can still customize their methods. Calling
* ResourceBundleloadBundle() in this class means that also the bundle files
* must be present here.
* <p>
* @param locale Locale from e.g. FacesContext
- * <p>
- * @return Initialized and loaded resource bundle
*/
- protected abstract ResourceBundle loadResourceBundle (final Locale locale);
+ protected abstract void loadResourceBundles (final Locale locale);
/**
* Shows a faces message for given causing exception. The message from the