deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-664 filter redundant messages
Date Sun, 13 Jul 2014 00:40:01 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master d45d87b04 -> 7d2666eab


DELTASPIKE-664 filter redundant messages


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/7d2666ea
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/7d2666ea
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/7d2666ea

Branch: refs/heads/master
Commit: 7d2666eabf63ce76e415543c877f1b087d72c853
Parents: d45d87b
Author: gpetracek <gpetracek@apache.org>
Authored: Sun Jul 13 02:34:01 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Sun Jul 13 02:34:01 2014 +0200

----------------------------------------------------------------------
 .../deltaspike/jsf/impl/util/JsfUtils.java      | 25 ++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7d2666ea/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
index 5252d7e..d360409 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
@@ -26,10 +26,12 @@ import org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData;
 import org.apache.deltaspike.jsf.impl.message.FacesMessageEntry;
 
 import javax.enterprise.context.ContextNotActiveException;
+import javax.faces.application.FacesMessage;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -298,12 +300,16 @@ public abstract class JsfUtils
 
             @SuppressWarnings({ "unchecked" })
             List<FacesMessageEntry> facesMessageEntryList = windowMetaData.getFacesMessageEntryList();
+            List<FacesMessage> originalMessageList = new ArrayList<FacesMessage>(facesContext.getMessageList());
 
             if (facesMessageEntryList != null)
             {
-                for (FacesMessageEntry facesMessageEntry : facesMessageEntryList)
+                for (FacesMessageEntry messageEntry : facesMessageEntryList)
                 {
-                    facesContext.addMessage(facesMessageEntry.getComponentId(), facesMessageEntry.getFacesMessage());
+                    if (isNewMessage(originalMessageList, messageEntry.getFacesMessage()))
+                    {
+                        facesContext.addMessage(messageEntry.getComponentId(), messageEntry.getFacesMessage());
+                    }
                 }
                 facesMessageEntryList.clear();
             }
@@ -313,4 +319,19 @@ public abstract class JsfUtils
             //TODO discuss how we handle it
         }
     }
+
+    public static boolean isNewMessage(List<FacesMessage> facesMessages, FacesMessage
messageToCheck)
+    {
+        for (FacesMessage facesMessage : facesMessages)
+        {
+            if ((facesMessage.getSummary() != null && facesMessage.getSummary().equals(messageToCheck.getSummary())
||
+                    facesMessage.getSummary() == null && messageToCheck.getSummary()
== null) &&
+                    (facesMessage.getDetail() != null && facesMessage.getDetail().equals(messageToCheck.getDetail())
||
+                        facesMessage.getDetail() == null && messageToCheck.getDetail()
== null))
+            {
+                return false;
+            }
+        }
+        return true;
+    }
 }


Mime
View raw message