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 2014/07/02 00:01:05 UTC
git commit: TAP5-1815 : Translators and/or Validators should override
the element's type attribute where appropriate to use HTML5 types
Repository: tapestry-5
Updated Branches:
refs/heads/master e457a43b8 -> 23f491d55
TAP5-1815 : Translators and/or Validators should override the <input>
element's type attribute where appropriate to use HTML5 types
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/23f491d5
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/23f491d5
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/23f491d5
Branch: refs/heads/master
Commit: 23f491d55fad08b1d6d74ee9f9768f4ef4f9dec9
Parents: e457a43
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Tue Jul 1 19:00:48 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Tue Jul 1 19:00:48 2014 -0300
----------------------------------------------------------------------
.../org/apache/tapestry5/SymbolConstants.java | 10 +++++
.../internal/services/Html5SupportImpl.java | 37 +++++++++++++++++
.../internal/translator/NumericTranslator.java | 11 ++++-
.../tapestry5/modules/TapestryModule.java | 8 +++-
.../apache/tapestry5/services/Html5Support.java | 33 +++++++++++++++
.../apache/tapestry5/test/TapestryTestCase.java | 7 +++-
.../org/apache/tapestry5/validator/Email.java | 14 ++++++-
.../org/apache/tapestry5/validator/Max.java | 11 ++++-
.../org/apache/tapestry5/validator/Min.java | 12 +++++-
.../org/apache/tapestry5/validator/Regexp.java | 5 ++-
.../apache/tapestry5/validator/Required.java | 12 +++++-
tapestry-core/src/test/app3/Html5Support.tml | 18 ++++++++
tapestry-core/src/test/app3/Login.tml | 3 ++
.../tapestry5/integration/app1/FormTests.java | 8 ++++
.../integration/app1/pages/ValidForm.java | 6 ++-
.../app3/AdditionalIntegrationTests.java | 35 +++++++++++++++-
.../integration/app3/pages/Html5Support.java | 43 ++++++++++++++++++++
.../integration/app3/services/AppModule.java | 2 +
.../apache/tapestry5/validator/EmailTest.java | 13 +++---
.../org/apache/tapestry5/validator/MaxTest.java | 10 +++--
.../org/apache/tapestry5/validator/MinTest.java | 7 ++--
.../tapestry5/validator/RequiredTest.java | 12 +++---
.../integration/app1/pages/ValidForm.tml | 5 +++
23 files changed, 289 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java b/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
index 28e96df..4ed67a8 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
@@ -17,6 +17,7 @@ import org.apache.tapestry5.corelib.components.BeanEditForm;
import org.apache.tapestry5.corelib.components.BeanEditor;
import org.apache.tapestry5.corelib.mixins.FormGroup;
import org.apache.tapestry5.internal.services.AssetDispatcher;
+import org.apache.tapestry5.services.Html5Support;
import org.apache.tapestry5.services.assets.AssetPathConstructor;
import org.apache.tapestry5.services.assets.ResourceMinimizer;
import org.apache.tapestry5.services.javascript.JavaScriptStack;
@@ -509,5 +510,14 @@ public class SymbolConstants
* @since 5.4
*/
public static final String OMIT_EXPIRATION_CACHE_CONTROL_HEADER = "tapestry.omit-expiration-cache-control-header";
+
+ /**
+ * Defines whether HTML5 features should be used. Value used in the default implementation of
+ * {@link Html5Support#isHtml5SupportEnabled()}. Default value: <code>false</code>.
+ *
+ * @since 5.4
+ * @see Html5Support#isHtml5SupportEnabled()
+ */
+ public static final String ENABLE_HTML5_SUPPORT = "tapestry.enable-html5-support";
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/Html5SupportImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/Html5SupportImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/Html5SupportImpl.java
new file mode 100644
index 0000000..7ffb741
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/Html5SupportImpl.java
@@ -0,0 +1,37 @@
+// Copyright 2014 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.internal.services;
+
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.services.Html5Support;
+
+public class Html5SupportImpl implements Html5Support
+{
+
+ final private boolean enabled;
+
+ public Html5SupportImpl(@Inject @Symbol(SymbolConstants.ENABLE_HTML5_SUPPORT) final boolean enabled)
+ {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public boolean isHtml5SupportEnabled()
+ {
+ return enabled;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/NumericTranslator.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/NumericTranslator.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/NumericTranslator.java
index 77d713a..0d6af86 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/NumericTranslator.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/NumericTranslator.java
@@ -1,4 +1,4 @@
-// Copyright 2009, 2012 The Apache Software Foundation
+// Copyright 2009, 2012, 2014 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.
@@ -18,6 +18,7 @@ import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.services.FormSupport;
+import org.apache.tapestry5.services.Html5Support;
import java.text.ParseException;
@@ -30,12 +31,14 @@ import java.text.ParseException;
public class NumericTranslator<T extends Number> extends AbstractTranslator<T>
{
private final NumericTranslatorSupport support;
+ private final Html5Support html5Support;
- public NumericTranslator(String name, Class<T> type, NumericTranslatorSupport support)
+ public NumericTranslator(String name, Class<T> type, NumericTranslatorSupport support, Html5Support html5Support)
{
super(name, type, support.getMessageKey(type));
this.support = support;
+ this.html5Support = html5Support;
}
public void render(Field field, String message, MarkupWriter writer, FormSupport formSupport)
@@ -44,6 +47,10 @@ public class NumericTranslator<T extends Number> extends AbstractTranslator<T>
{
support.setupTranslation(getType(), writer.getElement(), message);
}
+ if (html5Support.isHtml5SupportEnabled())
+ {
+ writer.getElement().forceAttributes("type", "number");
+ }
}
public T parseClient(Field field, String clientValue, String message) throws ValidationException
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index a9abd4b..50d03b4 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -376,6 +376,7 @@ public final class TapestryModule
binder.bind(PartialTemplateRenderer.class, PartialTemplateRendererImpl.class);
binder.bind(ExceptionReporter.class, ExceptionReporterImpl.class);
binder.bind(ComponentOverride.class, ComponentOverrideImpl.class).eagerLoad();
+ binder.bind(Html5Support.class, Html5SupportImpl.class);
}
// ========================================================================
@@ -888,7 +889,7 @@ public final class TapestryModule
* </ul>
*/
public static void contributeTranslatorSource(MappedConfiguration<Class, Translator> configuration,
- NumericTranslatorSupport support)
+ NumericTranslatorSupport support, Html5Support html5Support)
{
configuration.add(String.class, new StringTranslator());
@@ -901,7 +902,7 @@ public final class TapestryModule
{
String name = type.getSimpleName().toLowerCase();
- configuration.add(type, new NumericTranslator(name, type, support));
+ configuration.add(type, new NumericTranslator(name, type, support, html5Support));
}
}
@@ -2133,6 +2134,9 @@ public final class TapestryModule
configuration.add(SymbolConstants.STRICT_CSS_URL_REWRITING, "false");
configuration.add(SymbolConstants.EXCEPTION_REPORTS_DIR, "build/exceptions");
+
+ // TAP5-1815
+ configuration.add(SymbolConstants.ENABLE_HTML5_SUPPORT, "false");
}
/**
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/services/Html5Support.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/Html5Support.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/Html5Support.java
new file mode 100644
index 0000000..f8cc0d7
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/Html5Support.java
@@ -0,0 +1,33 @@
+// Copyright 2014 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.services;
+
+import org.apache.tapestry5.SymbolConstants;
+
+/**
+ * Service related to Tapestry's support of HTML5 features.
+ * @since 5.4
+ */
+public interface Html5Support
+{
+
+ /**
+ * Tells whether HTML5 is supported. The default implementation returns the value of the
+ * {@link SymbolConstants#ENABLE_HTML5_SUPPORT} symbol.
+ *
+ * @return <code>true</code> or <code>false</code>.
+ */
+ boolean isHtml5SupportEnabled();
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java b/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
index 143b40f..b615489 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
@@ -1,4 +1,4 @@
-// Copyright 2006-2013 The Apache Software Foundation
+// Copyright 2006-2014 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.
@@ -164,6 +164,11 @@ public abstract class TapestryTestCase extends IOCTestCase
return newMock(Field.class);
}
+ protected final Html5Support mockHtml5Support()
+ {
+ return newMock(Html5Support.class);
+ }
+
protected final FieldValidator mockFieldValidator()
{
return newMock(FieldValidator.class);
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java
index 46c736b..eae9b08 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2012 The Apache Software Foundation
+// Copyright 2008, 2012, 2014 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.
@@ -19,6 +19,7 @@ import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
+import org.apache.tapestry5.services.Html5Support;
import org.apache.tapestry5.services.javascript.DataConstants;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
@@ -31,12 +32,16 @@ import java.util.regex.Pattern;
*/
public class Email extends AbstractValidator<Void, String>
{
+
private static final Pattern PATTERN = Pattern
.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", Pattern.CASE_INSENSITIVE);
+
+ final private Html5Support html5Support;
- public Email(JavaScriptSupport javaScriptSupport)
+ public Email(JavaScriptSupport javaScriptSupport, Html5Support html5Support)
{
super(null, String.class, "invalid-email", javaScriptSupport);
+ this.html5Support = html5Support;
}
public void render(Field field, Void constraintValue, MessageFormatter formatter, MarkupWriter writer,
@@ -51,6 +56,11 @@ public class Email extends AbstractValidator<Void, String>
"data-validate-regexp", PATTERN.pattern(),
"data-regexp-message", formatter.toString());
}
+
+ if (html5Support.isHtml5SupportEnabled()) {
+ writer.getElement().forceAttributes("type", "email");
+ }
+
}
public void validate(Field field, Void constraintValue, MessageFormatter formatter, String value)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/validator/Max.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Max.java b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Max.java
index a4974ed..48c9b65 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Max.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Max.java
@@ -19,6 +19,7 @@ import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
+import org.apache.tapestry5.services.Html5Support;
import org.apache.tapestry5.services.javascript.DataConstants;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
@@ -27,9 +28,13 @@ import org.apache.tapestry5.services.javascript.JavaScriptSupport;
*/
public class Max extends AbstractValidator<Long, Number>
{
- public Max(JavaScriptSupport javaScriptSupport)
+
+ final private Html5Support html5Support;
+
+ public Max(JavaScriptSupport javaScriptSupport, Html5Support html5Support)
{
super(Long.class, Number.class, "max-integer", javaScriptSupport);
+ this.html5Support = html5Support;
}
public void validate(Field field, Long constraintValue, MessageFormatter formatter, Number value)
@@ -55,6 +60,10 @@ public class Max extends AbstractValidator<Long, Number>
"data-validate-max", constraintValue.toString(),
"data-max-message", buildMessage(formatter, field, constraintValue));
}
+ if (html5Support.isHtml5SupportEnabled())
+ {
+ writer.getElement().forceAttributes("type", "number", "max", String.valueOf(constraintValue));
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/validator/Min.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Min.java b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Min.java
index 0d49958..88931ce 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Min.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Min.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2012 The Apache Software Foundation
+// Copyright 2007, 2008, 2012, 2014 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.
@@ -19,15 +19,19 @@ import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
+import org.apache.tapestry5.services.Html5Support;
import org.apache.tapestry5.services.javascript.DataConstants;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
/* A vaidator that enforces that a number is greater than some minimum integer value. */
public class Min extends AbstractValidator<Long, Number>
{
- public Min(JavaScriptSupport javaScriptSupport)
+ final private Html5Support html5Support;
+
+ public Min(JavaScriptSupport javaScriptSupport, Html5Support html5Support)
{
super(Long.class, Number.class, "min-integer", javaScriptSupport);
+ this.html5Support = html5Support;
}
public void validate(Field field, Long constraintValue, MessageFormatter formatter, Number value)
@@ -52,5 +56,9 @@ public class Min extends AbstractValidator<Long, Number>
"data-validate-min", constraintValue.toString(),
"data-min-message", buildMessage(formatter, field, constraintValue));
}
+ if (html5Support.isHtml5SupportEnabled())
+ {
+ writer.getElement().forceAttributes("type", "number", "min", String.valueOf(constraintValue));
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/validator/Regexp.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Regexp.java b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Regexp.java
index 147da78..14e2911 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Regexp.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Regexp.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2012 The Apache Software Foundation
+// Copyright 2007, 2008, 2012, 2014 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.
@@ -49,7 +49,8 @@ public class Regexp extends AbstractValidator<Pattern, String>
writer.attributes(DataConstants.VALIDATION_ATTRIBUTE, true,
"data-validate-regexp", constraintValue.pattern(),
- "data-regexp-message", buildMessage(formatter, field, constraintValue));
+ "data-regexp-message", buildMessage(formatter, field, constraintValue),
+ "pattern", constraintValue.pattern());
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java
index a8d445e..8e17948 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2012 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2012, 2014 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.
@@ -20,6 +20,7 @@ import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.services.FormSupport;
+import org.apache.tapestry5.services.Html5Support;
import org.apache.tapestry5.services.javascript.DataConstants;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
@@ -28,9 +29,12 @@ import org.apache.tapestry5.services.javascript.JavaScriptSupport;
*/
public final class Required extends AbstractValidator<Void, Object>
{
- public Required(JavaScriptSupport javaScriptSupport)
+ final private Html5Support html5Support;
+
+ public Required(JavaScriptSupport javaScriptSupport, Html5Support html5Support)
{
super(null, Object.class, "required", javaScriptSupport);
+ this.html5Support = html5Support;
}
public void validate(Field field, Void constraintValue, MessageFormatter formatter, Object value)
@@ -66,5 +70,9 @@ public final class Required extends AbstractValidator<Void, Object>
"data-optionality", "required",
"data-required-message", buildMessage(formatter, field));
}
+ if (html5Support.isHtml5SupportEnabled())
+ {
+ writer.attributes("required", "required");
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/app3/Html5Support.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app3/Html5Support.tml b/tapestry-core/src/test/app3/Html5Support.tml
new file mode 100644
index 0000000..5776c36
--- /dev/null
+++ b/tapestry-core/src/test/app3/Html5Support.tml
@@ -0,0 +1,18 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <head>
+ <title>HTML 5 Support Demo</title>
+ </head>
+ <body>
+ <h1>HTML 5 Support Demo</h1>
+ <form t:type="Form">
+ <input t:type="TextField" t:id="integer" t:mixins="FormGroup"/>
+ <input t:type="TextField" t:id="required" t:validate="required" t:mixins="FormGroup"/>
+ <input t:type="TextField" t:id="email" t:validate="email" t:mixins="FormGroup"/>
+ <input t:type="TextField" t:id="minNumber" t:validate="min=1" t:mixins="FormGroup"/>
+ <input t:type="TextField" t:id="maxNumber" t:validate="max=10" t:mixins="FormGroup"/>
+ <input t:type="TextField" t:id="minMaxNumber" t:validate="min=2,max=4" t:mixins="FormGroup"/>
+ <input t:type="TextField" t:id="regexp" t:validate="regexp=[0-9]{2}" t:mixins="FormGroup"/>
+ <input type="submit"/>
+ </form>
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/app3/Login.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app3/Login.tml b/tapestry-core/src/test/app3/Login.tml
index 6937cd2..44f20cc 100644
--- a/tapestry-core/src/test/app3/Login.tml
+++ b/tapestry-core/src/test/app3/Login.tml
@@ -28,6 +28,9 @@
<li>
<t:pagelink page="OverridePageAtComponent">ComponentReplacer demo (using @Component to declare component instances)</t:pagelink>
</li>
+ <li>
+ <t:pagelink page="Html5Support">HTML 5 support demo</t:pagelink>
+ </li>
</ul>
</body>
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
index cf85b7d..4b8c76d 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
@@ -1211,4 +1211,12 @@ public class FormTests extends App1TestCase
}
+ /** TAP5-1815. In this webapp, HTML5 support is disabled, so we check whether it actually is disabled */
+ @Test
+ public void html5_support_disabled() throws Exception
+ {
+ openLinks("ValidForm");
+ assertEquals("text", getAttribute("emailValidator@type")); // if HTML5 support was enabled, this would be "email"
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidForm.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidForm.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidForm.java
index de9c3aa..6104746 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidForm.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ValidForm.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2014 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.
@@ -15,12 +15,16 @@
package org.apache.tapestry5.integration.app1.pages;
import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.integration.app1.data.IncidentData;
public class ValidForm
{
@Persist
private IncidentData incident;
+
+ @Property
+ private String emailValidator;
public IncidentData getIncident()
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
index 774df44..f94eff0 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/AdditionalIntegrationTests.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2011 The Apache Software Foundation
+// Copyright 2007, 2008, 2011, 2014 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.
@@ -109,4 +109,37 @@ public class AdditionalIntegrationTests extends TapestryCoreTestCase
}
+ /** TAP5-1815. In this webapp, HTML5 support is enabled, so we check whether it actually is enabled */
+ @Test
+ public void html5_support_enabled() throws Exception
+ {
+ open("/html5support");
+
+ // number translator should cause text fields to have type="number
+ assertEquals("number", getAttribute("integer@type"));
+
+ // required attribute for the required validator
+ assertEquals("required", getAttribute("required@required"));
+
+ // pattern attribute for the regexp validator
+ assertEquals("[0-9]{2}", getAttribute("regexp@pattern"));
+
+ // type="email" for the email validator
+ assertEquals("email", getAttribute("email@type"));
+
+ // type="number" for min validator
+ assertEquals("number", getAttribute("minNumber@type"));
+ assertEquals("1", getAttribute("minNumber@min"));
+
+ // type="number" for max validator
+ assertEquals("number", getAttribute("maxNumber@type"));
+ assertEquals("10", getAttribute("maxNumber@max"));
+
+ // type="number" for min and validators togenter
+ assertEquals("number", getAttribute("minMaxNumber@type"));
+ assertEquals("2", getAttribute("minMaxNumber@min"));
+ assertEquals("4", getAttribute("minMaxNumber@max"));
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java
new file mode 100644
index 0000000..2ee9029
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/pages/Html5Support.java
@@ -0,0 +1,43 @@
+// Copyright 2014 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.app3.pages;
+
+import org.apache.tapestry5.annotations.Property;
+
+public class Html5Support
+{
+
+ @Property
+ private Integer integer;
+
+ @Property
+ private String required;
+
+ @Property
+ private String email;
+
+ @Property
+ private String minNumber;
+
+ @Property
+ private String maxNumber;
+
+ @Property
+ private String minMaxNumber;
+
+ @Property
+ private String regexp;
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/services/AppModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/services/AppModule.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/services/AppModule.java
index 3fda2b3..bf68160 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/services/AppModule.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/services/AppModule.java
@@ -64,6 +64,8 @@ public class AppModule
configuration.add(SymbolConstants.FORM_GROUP_FORM_FIELD_WRAPPER_ELEMENT_CSS_CLASS, FORM_GROUP_FORM_FIELD_WRAPPER_ELEMENT_CSS_CLASS_VALUE);
configuration.add(SymbolConstants.FORM_FIELD_CSS_CLASS, FORM_FIELD_CSS_CLASS_VALUE);
+ configuration.add(SymbolConstants.ENABLE_HTML5_SUPPORT, "true");
+
}
@Contribute(Compatibility.class)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/validator/EmailTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/validator/EmailTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/validator/EmailTest.java
index 9a9b3e9..73d6d80 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/validator/EmailTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/validator/EmailTest.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2012 The Apache Software Foundation
+// Copyright 2008, 2012, 2014 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.
@@ -18,6 +18,7 @@ import org.apache.tapestry5.Field;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.MessageFormatter;
+import org.apache.tapestry5.services.Html5Support;
import org.testng.annotations.Test;
public class EmailTest extends InternalBaseTestCase
@@ -27,10 +28,11 @@ public class EmailTest extends InternalBaseTestCase
{
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
-
+ Html5Support html5Support = mockHtml5Support();
+
replay();
- Email validator = new Email(null);
+ Email validator = new Email(null, html5Support);
validator.validate(field, null, formatter, "myemail@mail.com");
@@ -42,10 +44,11 @@ public class EmailTest extends InternalBaseTestCase
{
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
-
+ Html5Support html5Support = mockHtml5Support();
+
replay();
- Email validator = new Email(null);
+ Email validator = new Email(null, html5Support);
try
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/validator/MaxTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/validator/MaxTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/validator/MaxTest.java
index 9c16fed..ecf3f84 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/validator/MaxTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/validator/MaxTest.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2012 The Apache Software Foundation
+// Copyright 2007, 2012, 2014 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.
@@ -16,12 +16,16 @@ package org.apache.tapestry5.validator;
import org.apache.tapestry5.Field;
import org.apache.tapestry5.ValidationException;
+import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.MessageFormatter;
+import org.apache.tapestry5.services.Html5Support;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class MaxTest extends InternalBaseTestCase
{
+
@Test
public void small_enough() throws Exception
{
@@ -31,7 +35,7 @@ public class MaxTest extends InternalBaseTestCase
replay();
- Max validator = new Max(null);
+ Max validator = new Max(null, mockHtml5Support());
for (int value = 48; value <= 50; value++)
validator.validate(field, constraint, formatter, value);
@@ -53,7 +57,7 @@ public class MaxTest extends InternalBaseTestCase
replay();
- Max validator = new Max(null);
+ Max validator = new Max(null, mockHtml5Support());
try
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/validator/MinTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/validator/MinTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/validator/MinTest.java
index 53e26ab..c76deb1 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/validator/MinTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/validator/MinTest.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2012 The Apache Software Foundation
+// Copyright 2007, 2012, 2014 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.
@@ -18,6 +18,7 @@ import org.apache.tapestry5.Field;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.MessageFormatter;
+import org.apache.tapestry5.services.Html5Support;
import org.testng.annotations.Test;
public class MinTest extends InternalBaseTestCase
@@ -31,7 +32,7 @@ public class MinTest extends InternalBaseTestCase
replay();
- Min validator = new Min(null);
+ Min validator = new Min(null, mockHtml5Support());
for (int value = 50; value < 52; value++)
validator.validate(field, constraint, formatter, value);
@@ -53,7 +54,7 @@ public class MinTest extends InternalBaseTestCase
replay();
- Min validator = new Min(null);
+ Min validator = new Min(null, mockHtml5Support());
try
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java
index 7794a97..3f53d9e 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2012 The Apache Software Foundation
+// Copyright 2006, 2007, 2012, 2014 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.
@@ -36,7 +36,7 @@ public class RequiredTest extends TapestryTestCase
try
{
- new Required(null).validate(field, null, formatter, null);
+ new Required(null, mockHtml5Support()).validate(field, null, formatter, null);
unreachable();
}
catch (ValidationException ex)
@@ -59,7 +59,7 @@ public class RequiredTest extends TapestryTestCase
try
{
- new Required(null).validate(field, null, formatter, "");
+ new Required(null, mockHtml5Support()).validate(field, null, formatter, "");
unreachable();
}
catch (ValidationException ex)
@@ -82,7 +82,7 @@ public class RequiredTest extends TapestryTestCase
try
{
- new Required(null).validate(field, null, formatter, Arrays.asList());
+ new Required(null, mockHtml5Support()).validate(field, null, formatter, Arrays.asList());
unreachable();
}
catch (ValidationException ex)
@@ -101,7 +101,7 @@ public class RequiredTest extends TapestryTestCase
replay();
- new Required(null).validate(field, null, formatter, Arrays.asList("A", "B"));
+ new Required(null, mockHtml5Support()).validate(field, null, formatter, Arrays.asList("A", "B"));
verify();
}
@@ -114,7 +114,7 @@ public class RequiredTest extends TapestryTestCase
replay();
- new Required(null).validate(field, null, formatter, "not null");
+ new Required(null, mockHtml5Support()).validate(field, null, formatter, "not null");
verify();
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/23f491d5/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/ValidForm.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/ValidForm.tml b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/ValidForm.tml
index a81c1d8..da7c4e8 100644
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/ValidForm.tml
+++ b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/ValidForm.tml
@@ -25,6 +25,11 @@
<input t:type="TextField" t:id="hours"
value="incident.hours" size="10" t:validate="required"/>
</div>
+ <div class="form-group">
+ <t:label for="emailValidator"/>
+ <input t:type="TextField" t:id="emailValidator"
+ value="emailValidator" size="10" t:validate="email"/>
+ </div>
<input type="submit" class="btn btn-primary"/>
</t:form>