You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2014/06/30 23:09:07 UTC
git commit: TAP5-1290: Add required flag to
@ActivationRequestParameter annotation
Repository: tapestry-5
Updated Branches:
refs/heads/master d9a795f1a -> 7a2f98c8e
TAP5-1290: Add required flag to @ActivationRequestParameter annotation
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/7a2f98c8
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/7a2f98c8
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/7a2f98c8
Branch: refs/heads/master
Commit: 7a2f98c8edb9c0ab90b664e38ab82d420e0f446c
Parents: d9a795f
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Jun 30 14:08:51 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Jun 30 14:09:03 2014 -0700
----------------------------------------------------------------------
.../annotations/ActivationRequestParameter.java | 12 ++++++++----
.../transform/ActivationRequestParameterWorker.java | 16 ++++++++++++----
.../app1/ActivationRequestParameterTests.groovy | 11 +++++++++--
.../tapestry5/integration/app1/pages/Index.java | 2 ++
.../integration/app1/pages/MissingRequiredARP.java | 9 +++++++++
5 files changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7a2f98c8/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationRequestParameter.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationRequestParameter.java b/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationRequestParameter.java
index d5f8086..f7e264d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationRequestParameter.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationRequestParameter.java
@@ -1,5 +1,3 @@
-// Copyright 2010, 2013 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
@@ -47,7 +45,7 @@ import org.apache.tapestry5.services.ValueEncoderSource;
* Fields annotated with ActivationRequestParameter are <em>not</em> considered persistent (its a process parallel to the one
* related to the {@link Persist} annotation). Invoking {@link ComponentResources#discardPersistentFieldChanges()} will
* <em>not</em> affect annotated fields, only assigning them back to null will.
- *
+ *
* @see RequestParameter
* @see ValueEncoder
*/
@@ -62,5 +60,11 @@ public @interface ActivationRequestParameter
/** The name of the query parameter, which defaults to the name of the field. */
String value() default "";
- // TODO: Attributes to limit it to just render links, or just component event links?
+ /**
+ * If true then a null value is an error. If false, then a null value will result in no update to the field. Either way,
+ * a null field value will result in no query parameter added to a {@linkplain org.apache.tapestry5.Link generated link}.
+ *
+ * @since 5.4
+ */
+ boolean required() default false;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7a2f98c8/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ActivationRequestParameterWorker.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ActivationRequestParameterWorker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ActivationRequestParameterWorker.java
index 29afeef..55dfee0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ActivationRequestParameterWorker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ActivationRequestParameterWorker.java
@@ -1,5 +1,3 @@
-// Copyright 2010, 2011 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
@@ -19,6 +17,7 @@ import org.apache.tapestry5.Link;
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.annotations.ActivationRequestParameter;
import org.apache.tapestry5.internal.services.ComponentClassCache;
+import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.apache.tapestry5.ioc.util.IdAllocator;
import org.apache.tapestry5.model.MutableComponentModel;
import org.apache.tapestry5.plastic.FieldHandle;
@@ -86,7 +85,7 @@ public class ActivationRequestParameterWorker implements ComponentClassTransform
String fieldName = String.format("%s.%s", field.getPlasticClass().getClassName(), field.getName());
- setValueFromInitializeEventHandler(support, fieldName, handle, parameterName, encoder, urlEncoder);
+ setValueFromInitializeEventHandler(support, fieldName, annotation.required(), handle, parameterName, encoder, urlEncoder);
decorateLinks(support, fieldName, handle, parameterName, encoder, urlEncoder);
@@ -112,7 +111,7 @@ public class ActivationRequestParameterWorker implements ComponentClassTransform
}
@SuppressWarnings("all")
- private void setValueFromInitializeEventHandler(TransformationSupport support, String fieldName, final FieldHandle handle,
+ private void setValueFromInitializeEventHandler(final TransformationSupport support, final String fieldName, final boolean required, final FieldHandle handle,
final String parameterName, final ValueEncoder encoder, final URLEncoder urlEncoder)
{
ComponentEventHandler handler = new ComponentEventHandler()
@@ -122,7 +121,16 @@ public class ActivationRequestParameterWorker implements ComponentClassTransform
String clientValue = request.getParameter(parameterName);
if (clientValue == null)
+ {
+ if (required)
+ {
+ throw new TapestryException(String.format("Activation request parameter field %s is marked as required, but query parameter '%s' is null.",
+ fieldName,
+ parameterName), null);
+ }
+
return;
+ }
// TAP5-1768: unescape encoded value
clientValue = urlEncoder.decode(clientValue);
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7a2f98c8/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy
index 7688426..416468a 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy
@@ -1,5 +1,3 @@
-// Copyright 2010-2013 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
@@ -63,4 +61,13 @@ class ActivationRequestParameterTests extends App1TestCase
assertText "click-count", "1"
assertText "selected-click-count", "2"
}
+
+ @Test
+ public void required_arp_with_missing_parameter_is_error() {
+
+ openLinks "Missing Query Parameter for @ActivationRequestParameter"
+
+ assertTextPresent"Activation request parameter field org.apache.tapestry5.integration.app1.pages.MissingRequiredARP.missingARP is marked as required, but query parameter 'missingARP' is null."
+
+ }
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7a2f98c8/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
index 85d0987..2d9876c 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
@@ -57,6 +57,8 @@ public class Index
private static final List<Item> ITEMS = CollectionFactory
.newList(
+ new Item("MissingRequiredARP", "Missing Query Parameter for @ActivationRequestParameter", "Activating a page with a required @ActivationRequestParameter, but no matching query parameter, is an error."),
+
new Item ("DateFieldValidationDemo", "DateField Validation Demo",
"Use of DateField component when client validation is disabled."),
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7a2f98c8/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingRequiredARP.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingRequiredARP.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingRequiredARP.java
new file mode 100644
index 0000000..1d569d3
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/MissingRequiredARP.java
@@ -0,0 +1,9 @@
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.annotations.ActivationRequestParameter;
+
+public class MissingRequiredARP
+{
+ @ActivationRequestParameter(required = true)
+ private String missingARP;
+}