You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2010/12/18 20:23:21 UTC

svn commit: r1050698 - in /wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form: EmailTextField.java NumberTextField.java UrlTextField.java

Author: mgrigorov
Date: Sat Dec 18 19:23:21 2010
New Revision: 1050698

URL: http://svn.apache.org/viewvc?rev=1050698&view=rev
Log:
WICKET-3241 Add support for the new HTML 5 input types

Add text fields specific for html5 types: number, email and url

Added:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/EmailTextField.java   (with props)
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/NumberTextField.java   (with props)
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/UrlTextField.java   (with props)

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/EmailTextField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/EmailTextField.java?rev=1050698&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/EmailTextField.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/EmailTextField.java Sat Dec 18 19:23:21 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.wicket.markup.html.form;
+
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.validation.validator.EmailAddressValidator;
+
+/**
+ * A {@link TextField} for HTML5 &lt;input&gt; with type <strong>email</strong>.
+ * 
+ * <p>
+ * Automatically validates that the input is a valid email address.
+ */
+public class EmailTextField extends TextField<String>
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            component id
+	 * @param emailAddress
+	 *            the email input value
+	 */
+	public EmailTextField(String id, final String emailAddress)
+	{
+		this(id, new Model<String>(emailAddress));
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            see Component
+	 * @param model
+	 *            the model
+	 */
+	public EmailTextField(String id, IModel<String> model)
+	{
+		super(id, model, String.class);
+
+		add(EmailAddressValidator.getInstance());
+	}
+
+	@Override
+	protected String getInputType()
+	{
+		return "email";
+	}
+}

Propchange: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/EmailTextField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/NumberTextField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/NumberTextField.java?rev=1050698&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/NumberTextField.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/NumberTextField.java Sat Dec 18 19:23:21 2010
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.wicket.markup.html.form;
+
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.validation.validator.RangeValidator;
+
+/**
+ * A {@link TextField} for HTML5 &lt;input&gt; with type <strong>number</strong>.
+ * 
+ * <p>
+ * Automatically validates the input against the configured {@link #setMinimum(Double) min} and
+ * {@link #setMaximum(Double) max} attributes. If any of them is <code>null</code> then
+ * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} are used respectfully.
+ */
+public class NumberTextField extends TextField<Double>
+{
+	private static final long serialVersionUID = 1L;
+
+	private RangeValidator<Double> validator;
+
+	private Double minimum;
+
+	private Double maximum;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            component id
+	 */
+	public NumberTextField(String id)
+	{
+		this(id, null);
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            see Component
+	 * @param model
+	 *            the model
+	 */
+	public NumberTextField(String id, IModel<Double> model)
+	{
+		super(id, model, Double.class);
+
+		validator = null;
+		minimum = null;
+		maximum = null;
+	}
+
+	/**
+	 * @param minimum
+	 *            the minimum allowed value
+	 * @return this instance
+	 */
+	public NumberTextField setMinimum(final Double minimum)
+	{
+		this.minimum = minimum;
+		return this;
+	}
+
+	/**
+	 * @param maximum
+	 *            the maximum allowed value
+	 * @return this instance
+	 */
+	public NumberTextField setMaximum(final Double maximum)
+	{
+		this.maximum = maximum;
+		return this;
+	}
+
+	@Override
+	public void onConfigure()
+	{
+		super.onConfigure();
+
+		if (validator != null)
+		{
+			remove(validator);
+		}
+
+		Double min = minimum;
+		Double max = maximum;
+
+		if (min == null)
+		{
+			min = Double.MIN_VALUE;
+		}
+
+		if (max == null)
+		{
+			max = Double.MAX_VALUE;
+		}
+
+		validator = new RangeValidator<Double>(min, max);
+		add(validator);
+	}
+
+	@Override
+	protected String getInputType()
+	{
+		return "number";
+	}
+}

Propchange: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/NumberTextField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/UrlTextField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/UrlTextField.java?rev=1050698&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/UrlTextField.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/UrlTextField.java Sat Dec 18 19:23:21 2010
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.wicket.markup.html.form;
+
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.validation.validator.UrlValidator;
+
+/**
+ * A {@link TextField} for HTML5 &lt;input&gt; with type <strong>url</strong>.
+ * 
+ * <p>
+ * Automatically validates the input that it is a valid Url.
+ */
+public class UrlTextField extends TextField<String>
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            component id
+	 * @param url
+	 *            the url input value
+	 */
+	public UrlTextField(String id, final String url)
+	{
+		this(id, new Model<String>(url));
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            see Component
+	 * @param model
+	 *            the model
+	 */
+	public UrlTextField(String id, IModel<String> model)
+	{
+		super(id, model, String.class);
+
+		// XXX does this validator needs UrlValidator#options ?!
+		add(new UrlValidator());
+	}
+
+	@Override
+	protected String getInputType()
+	{
+		return "url";
+	}
+}

Propchange: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/UrlTextField.java
------------------------------------------------------------------------------
    svn:eol-style = native