]> git.mxchange.org Git - jcoreee.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 8 Apr 2020 16:53:26 +0000 (18:53 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 8 Apr 2020 16:53:26 +0000 (18:53 +0200)
- added severity (FacesMessage) to parameter lists so not the default "info" is
  always taken

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java

index 699c5a2e5d7b8b96abb9cf8397f5ad1a751d8a54..e8116ea2291ff22b7a15747cbdd2e5fd65e2e8c8 100644 (file)
@@ -107,7 +107,7 @@ public abstract class BaseFacesBean implements Serializable {
                        return false;
                } else if (!(value instanceof Comparable)) {
                        // Not castable
-                       throw new ClassCastException("value is not instance of Comparable");
+                       throw new ClassCastException("value is not instance of Comparable"); //NOI18N
                }
 
                // Do the cast and compare
@@ -184,11 +184,12 @@ public abstract class BaseFacesBean implements Serializable {
 
                // Loop through all
                for (final ResourceBundle bundle : getBundles()) {
-                       // Found message?
                        // Try it
                        try {
                                // Get message
                                message = bundle.getString(i18nKey);
+
+                               // Skip further iterations
                                break;
                        } catch (final MissingResourceException ex) {
                                // Did not find it, ignored
@@ -272,10 +273,26 @@ public abstract class BaseFacesBean implements Serializable {
         * <p>
         * @param clientId Client id to send message to
         * @param cause    Causing exception
+        * @param severity Severity
         */
-       protected void showFacesMessage (final String clientId, final Throwable cause) {
+       protected void showFacesMessage (final String clientId, final Throwable cause, final FacesMessage.Severity severity) {
+               // Both parameter must be valid
+               if (null == clientId) {
+                       // Throw NPE
+                       throw new NullPointerException("clientId is null"); //NOI18N
+               } else if (clientId.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("clientId is null"); //NOI18N
+               } else if (null == cause) {
+                       // Throw NPE
+                       throw new NullPointerException("cause is null"); //NOI18N
+               } else if (null == severity) {
+                       // Throw NPE
+                       throw new NullPointerException("severity is null"); //NOI18N
+               }
+
                // Get context and add message
-               this.showFacesMessage(clientId, cause.getMessage());
+               this.showFacesMessage(clientId, cause.getMessage(), severity);
        }
 
        /**
@@ -283,11 +300,12 @@ public abstract class BaseFacesBean implements Serializable {
         * <p>
         * @param clientId Client id to send message to
         * @param i18nKey  Message key
+        * @param severity Severity
         * <p>
         * @throws NullPointerException If clientId or i18nKey is null
         * @throws IllegalArgumentException If clientId or i18nKey is empty
         */
-       protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException {
+       protected void showFacesMessage (final String clientId, final String i18nKey, final FacesMessage.Severity severity) throws NullPointerException, IllegalArgumentException {
                // Both parameter must be valid
                if (null == clientId) {
                        // Throw NPE
@@ -301,13 +319,16 @@ public abstract class BaseFacesBean implements Serializable {
                } else if (i18nKey.isEmpty()) {
                        // Is empty
                        throw new IllegalArgumentException("i18nKey is null"); //NOI18N
+               } else if (null == severity) {
+                       // Throw NPE
+                       throw new NullPointerException("severity is null"); //NOI18N
                }
 
                // Get message from bundle
                final String message = this.getMessageFromBundle(i18nKey);
 
                // Get context and add message
-               FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
+               FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(severity, message, message));
        }
 
 }