Author: hlship
Date: Fri Sep 12 12:40:48 2008
New Revision: 694786
URL: http://svn.apache.org/viewvc?rev=694786&view=rev
Log:
TAPESTRY-2438: ValidationException thrown from onValidateForm() should be
recorded for the Form, but instead is treated as an unexpected error
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ValidateFormValidationExceptionDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidateFormValidationExceptionDemo.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java?rev=694786&r1=694785&r2=694786&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
Fri Sep 12 12:40:48 2008
@@ -31,6 +31,7 @@
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.TapestryException;
+import org.apache.tapestry5.ioc.util.ExceptionUtils;
import org.apache.tapestry5.runtime.Component;
import org.apache.tapestry5.services.*;
import org.slf4j.Logger;
@@ -350,7 +351,7 @@
formSupport.executeDeferred();
- resources.triggerContextEvent(VALIDATE_FORM, context, callback);
+ fireValidateFormEvent(context, callback);
if (callback.isAborted()) return true;
@@ -380,6 +381,26 @@
}
}
+ private void fireValidateFormEvent(EventContext context,
ComponentResultProcessorWrapper callback)
+ {
+ try
+ {
+ resources.triggerContextEvent(VALIDATE_FORM, context, callback);
+ }
+ catch (RuntimeException ex)
+ {
+ ValidationException ve = ExceptionUtils.findCause(ex,
ValidationException.class);
+
+ if (ve != null)
+ {
+ recordError(ve.getMessage());
+ return;
+ }
+
+ throw ex;
+ }
+ }
+
/**
* Pulls the stored actions out of the request, converts them from MIME
stream back to object stream and then
* objects, and executes them.
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ValidateFormValidationExceptionDemo.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ValidateFormValidationExceptionDemo.tml?rev=694786&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ValidateFormValidationExceptionDemo.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ValidateFormValidationExceptionDemo.tml
Fri Sep 12 12:40:48 2008
@@ -0,0 +1,14 @@
+<html t:type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <h1>ValidateForm ValidationException Demo</h1>
+
+
+ <t:form t:id="form">
+ <t:errors/>
+ <input type="submit"/>
+ </t:form>
+
+ <p>
+ Last event:
+ <span id="event">${event}</span>
+ </p>
+</html>
\ No newline at end of file
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=694786&r1=694785&r2=694786&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
Fri Sep 12 12:40:48 2008
@@ -2266,4 +2266,18 @@
assertTextPresent("Demonstrates the use of the @Inject annotation.");
}
+
+ /**
+ * TAPESTRY-2438
+ */
+ public void validation_exception_thrown_from_validate_form_event_handler()
+ {
+ start("ValidationForm ValidationException Demo");
+
+ clickAndWait(SUBMIT);
+
+ assertTextPresent("From event handler method.");
+
+ assertText("event", "failure");
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java?rev=694786&r1=694785&r2=694786&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
Fri Sep 12 12:40:48 2008
@@ -65,6 +65,10 @@
private static final List<Item> ITEMS = CollectionFactory.newList(
+ new Item("ValidateFormValidationExceptionDemo",
+ "ValidationForm ValidationException Demo",
+ "Throwing a ValidationException from the validateForm
event handler."),
+
new Item("ClientFormatDemo", "Client Format Validation",
"Client-side input format validation"),
new Item("ShortGrid", "Short Grid",
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidateFormValidationExceptionDemo.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidateFormValidationExceptionDemo.java?rev=694786&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidateFormValidationExceptionDemo.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidateFormValidationExceptionDemo.java
Fri Sep 12 12:40:48 2008
@@ -0,0 +1,35 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.ValidationException;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+
+public class ValidateFormValidationExceptionDemo
+{
+ @Property
+ @Persist
+ private String event;
+
+ void onValidateFormFromForm() throws ValidationException
+ {
+ throw new ValidationException("From event handler method.");
+ }
+
+ void onSuccessFromForm() { event = "success"; }
+
+ void onFailureFromForm() { event = "failure"; }
+}