From: Roland Häder Date: Wed, 8 Apr 2020 16:53:26 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bf41754b3ff3b04b58b0bbd3bda7d504a0dd4c8a;p=jcoreee.git Continued: - added severity (FacesMessage) to parameter lists so not the default "info" is always taken Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java b/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java index 699c5a2..e8116ea 100644 --- a/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java +++ b/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java @@ -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 { *

* @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 { *

* @param clientId Client id to send message to * @param i18nKey Message key + * @param severity Severity *

* @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)); } }