Author: jogep
Date: Mon Mar  7 21:44:34 2011
New Revision: 1078966

URL: http://svn.apache.org/viewvc?rev=1078966&view=rev
Log:
WW-3395: Client Validation don't display Global Messages

Modified:
    
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js

Modified: 
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js?rev=1078966&r1=1078965&r2=1078966&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js 
(original)
+++ 
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js 
Mon Mar  7 21:44:34 2011
@@ -32,24 +32,50 @@ StrutsUtils.getValidationErrors = functi
 };
 
 StrutsUtils.clearValidationErrors = function(form) {
-  var firstNode = StrutsUtils.firstElement(form);
-  var xhtml = firstNode.tagName.toLowerCase() == "table";
-  
-  if(xhtml) {
-    clearErrorMessagesXHTML(form);
-    clearErrorLabelsXHTML(form);
-  } else {
-    clearErrorMessagesCSS(form);
-    clearErrorLabelsCSS(form);
-  }
-};  
+    var firstNode = StrutsUtils.firstElement(form);
+    var xhtml = firstNode.tagName.toLowerCase() == "table";
+
+    if(xhtml) {
+        clearErrorMessagesXHTML(form);
+        clearErrorLabelsXHTML(form);
+    } else {
+        clearErrorMessagesCSS(form);
+        clearErrorLabelsCSS(form);
+    }
+
+    //clear previous global error messages
+       if(StrutsUtils.errorLists[form] && StrutsUtils.errorLists[form] !== 
null) {
+               form.parentNode.removeChild(StrutsUtils.errorLists[form]);
+               StrutsUtils.errorLists[form] = null;
+       }
+
+};
+
+StrutsUtils.errorLists = [];
 
 // shows validation errors using functions from xhtml/validation.js
 // or css_xhtml/validation.js
 StrutsUtils.showValidationErrors = function(form, errors) {
-  StrutsUtils.clearValidationErrors(form, errors);
+    StrutsUtils.clearValidationErrors(form, errors);
+
+       if (errors.errors) {
+               var errorList = document.createElement("ul");
+               errorList.setAttribute("class", "errorMessage");
+               errorList.setAttribute("className", "errorMessage"); // ie hack 
cause ie does not support setAttribute
+
+               for ( var l = 0; l < errors.errors.length; l++) {
+                       var item = document.createElement("li");
+                       var itemText = 
document.createTextNode(errors.errors[l]);
+                       item.appendChild(itemText);
+
+                       errorList.appendChild(item);
+               }
+               
+               form.parentNode.insertBefore(errorList, form);
+               StrutsUtils.errorLists[form] = errorList;
+       }
 
-  var firstNode = StrutsUtils.firstElement(form);
+       var firstNode = StrutsUtils.firstElement(form);
   var xhtml = firstNode.tagName.toLowerCase() == "table";  
   if(errors.fieldErrors) {
     for(var fieldName in errors.fieldErrors) {


Reply via email to