001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.html.form;
018
019import org.apache.wicket.model.IModel;
020import org.apache.wicket.model.Model;
021import org.apache.wicket.validation.validator.UrlValidator;
022
023/**
024 * A {@link TextField} for HTML5 &lt;input&gt; with type <em>url</em>.
025 * 
026 * <p>
027 * Automatically validates the input that it is a valid Url.
028 */
029public class UrlTextField extends TextField<String>
030{
031        private static final long serialVersionUID = 1L;
032
033        /**
034         * Construct.
035         * 
036         * @param id
037         *            component id
038         * @param url
039         *            the url input value
040         */
041        public UrlTextField(String id, final String url)
042        {
043                this(id, Model.of(url));
044        }
045
046        /**
047         * Construct.
048         * 
049         * @param id
050         *            the component id
051         * @param model
052         *            the input value
053         */
054        public UrlTextField(String id, IModel<String> model)
055        {
056                this(id, model, new UrlValidator());
057        }
058
059        /**
060         * Construct.
061         * 
062         * @param id
063         *            the component id
064         * @param model
065         *            the input value
066         * @param urlValidator
067         *            the validator that will check the correctness of the input value
068         */
069        public UrlTextField(String id, IModel<String> model, UrlValidator urlValidator)
070        {
071                super(id, model, String.class);
072
073                add(urlValidator);
074        }
075
076        @Override
077        protected String[] getInputTypes()
078        {
079                return new String[] {"url"};
080        }
081}