From bf41754b3ff3b04b58b0bbd3bda7d504a0dd4c8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 8 Apr 2020 18:53:26 +0200 Subject: [PATCH] Continued: - added severity (FacesMessage) to parameter lists so not the default "info" is always taken MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jcoreee/bean/faces/BaseFacesBean.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) 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)); } } -- 2.39.5