struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r751795 - /struts/sandbox/trunk/s2-jquery-showcase/src/main/webapp/WEB-INF/content/simple-theme/SimpleFormPostAjaxResponse-input.jsp
Date Mon, 09 Mar 2009 19:13:09 GMT
Author: wesw
Date: Mon Mar  9 19:13:09 2009
New Revision: 751795

URL: http://svn.apache.org/viewvc?rev=751795&view=rev
Log:
testing out AJAX Post / AJAX Response

Modified:
    struts/sandbox/trunk/s2-jquery-showcase/src/main/webapp/WEB-INF/content/simple-theme/SimpleFormPostAjaxResponse-input.jsp

Modified: struts/sandbox/trunk/s2-jquery-showcase/src/main/webapp/WEB-INF/content/simple-theme/SimpleFormPostAjaxResponse-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/s2-jquery-showcase/src/main/webapp/WEB-INF/content/simple-theme/SimpleFormPostAjaxResponse-input.jsp?rev=751795&r1=751794&r2=751795&view=diff
==============================================================================
--- struts/sandbox/trunk/s2-jquery-showcase/src/main/webapp/WEB-INF/content/simple-theme/SimpleFormPostAjaxResponse-input.jsp
(original)
+++ struts/sandbox/trunk/s2-jquery-showcase/src/main/webapp/WEB-INF/content/simple-theme/SimpleFormPostAjaxResponse-input.jsp
Mon Mar  9 19:13:09 2009
@@ -6,7 +6,34 @@
 <sjx:head />
     <script type="text/javascript">
         function handleAjaxResponse(data, textStatus) {
-            $("#messages").append(data + "<br />\n");
+            var formData = StrutsJQueryUtils.keyValueizeForm("indexForm");
+            formData['struts.enableJSONValidation'] = true;
+            $.post("/s2-jquery-showcase/form/SimpleFormPostNonAjaxResponse", formData, handleFormCb_indexForm);
+            return false;
+        }
+
+        function handleFormCb_indexForm(responseText, textStatus) {
+
+            //clear previous validation errors, if any
+            $("#errors").empty();
+
+            //get errors from response
+            var errorsObject = StrutsJQueryUtils.getValidationErrors(responseText);
+
+            //show errors, if any
+            if (errorsObject && errorsObject.fieldErrors) {
+                for (var fieldName in errorsObject.fieldErrors) {
+                    for (var i = 0; i < errorsObject.fieldErrors[fieldName].length; i++)
{
+                        $("#errors").html(
+                                $("#errors").html() + "<br/>" + errorsObject.fieldErrors[fieldName][i]
+                                );
+                    }
+                }
+            }
+            else {
+                $("#messages").append(responseText + "<br />\n");
+                // alert(textStatus);
+            }
         }
     </script>
 </head>



Mime
View raw message