You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2020/12/29 21:43:24 UTC

[tapestry-5] branch master updated: TAP5-2655: annotation to disable validation in event handler methods

This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a26266  TAP5-2655: annotation to disable validation in event handler methods
9a26266 is described below

commit 9a262668b8333496d0813f3ed519f4014f6616d8
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Tue Dec 29 18:43:01 2020 -0300

    TAP5-2655: annotation to disable validation in event handler methods
---
 .../internal/transform/OnEventWorker.java          |  5 ++++
 .../integration/app1/pages/ActionViaLinkDemo.java  | 16 ++++++++++++
 .../tapestry5/annotations/DisableStrictChecks.java | 30 ++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
index 506048e..8436b26 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
@@ -23,6 +23,7 @@ import org.apache.tapestry5.ValueEncoder;
 import org.apache.tapestry5.annotations.OnEvent;
 import org.apache.tapestry5.annotations.PublishEvent;
 import org.apache.tapestry5.annotations.RequestParameter;
+import org.apache.tapestry5.annotations.DisableStrictChecks;
 import org.apache.tapestry5.commons.internal.util.TapestryException;
 import org.apache.tapestry5.commons.util.CollectionFactory;
 import org.apache.tapestry5.commons.util.ExceptionUtils;
@@ -406,6 +407,10 @@ public class OnEventWorker implements ComponentClassTransformWorker2
                 {
                     return null;
                 }
+                if (element.method.getAnnotation(DisableStrictChecks.class) != null)
+                {
+                    return null;
+                }
 
                 return new ComponentIdValidator(element.componentId, element.method.getMethodIdentifier());
             }
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
index 83622e5..a3cfc8d 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
@@ -15,6 +15,8 @@ package org.apache.tapestry5.integration.app1.pages;
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.PersistenceConstants;
 import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.DisableStrictChecks;
+import org.apache.tapestry5.annotations.OnEvent;
 import org.apache.tapestry5.http.Link;
 import org.apache.tapestry5.ioc.annotations.Inject;
 
@@ -48,4 +50,18 @@ public class ActionViaLinkDemo
 
         return link.toURI();
     }
+    
+    @DisableStrictChecks
+    void onActionFromNonExistent() 
+    {
+        
+    }
+    
+    @DisableStrictChecks
+    @OnEvent(value = "test", component = "nonExistent")
+    void someEventHandlerMethod() 
+    {
+        
+    }
+
 }
diff --git a/tapestry5-annotations/src/main/java/org/apache/tapestry5/annotations/DisableStrictChecks.java b/tapestry5-annotations/src/main/java/org/apache/tapestry5/annotations/DisableStrictChecks.java
new file mode 100644
index 0000000..6ce849e
--- /dev/null
+++ b/tapestry5-annotations/src/main/java/org/apache/tapestry5/annotations/DisableStrictChecks.java
@@ -0,0 +1,30 @@
+// 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.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Disables strict checks Tapestry-IoC or Tapestry may perform on methods. So far, this annotation
+ * can be used in Tapestry event handler methods to disable the check on whether they match
+ * a component id which actually exists.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(METHOD)
+public @interface DisableStrictChecks 
+{
+
+}