You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by cn...@apache.org on 2017/02/21 08:49:05 UTC

struts git commit: fixed JS to show validation errors as server is now sending status code 400

Repository: struts
Updated Branches:
  refs/heads/master 9fcf2dfca -> c8630ac56


fixed JS to show validation errors as server is now sending status code 400


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

Branch: refs/heads/master
Commit: c8630ac56d9535cafa6c2df62bb63663dec70ade
Parents: 9fcf2df
Author: cnenning <cn...@apache.org>
Authored: Tue Feb 21 09:47:59 2017 +0100
Committer: cnenning <cn...@apache.org>
Committed: Tue Feb 21 09:47:59 2017 +0100

----------------------------------------------------------------------
 .../src/main/webapp/WEB-INF/validation/ajaxFormSubmit.jsp   | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/c8630ac5/apps/showcase/src/main/webapp/WEB-INF/validation/ajaxFormSubmit.jsp
----------------------------------------------------------------------
diff --git a/apps/showcase/src/main/webapp/WEB-INF/validation/ajaxFormSubmit.jsp b/apps/showcase/src/main/webapp/WEB-INF/validation/ajaxFormSubmit.jsp
index f30403f..da07ff1 100644
--- a/apps/showcase/src/main/webapp/WEB-INF/validation/ajaxFormSubmit.jsp
+++ b/apps/showcase/src/main/webapp/WEB-INF/validation/ajaxFormSubmit.jsp
@@ -112,8 +112,13 @@ function ajaxFormValidation(event) {
             if (restoreFunction) {
                 restoreFunction();
             }
-            // show user an error message
-            _handleValidationResult(_form, {errors: ['Network or server error!']})
+            // struts sends status code 400 when validation errors are present
+            if (xhr.status === 400) {
+                _handleValidationResult(_form, JSON.parse(xhr.responseText))
+            } else {
+                // a real error occurred -> show user an error message
+                _handleValidationResult(_form, {errors: ['Network or server error!']})
+            }
         }
     }