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.IValidator; 022import org.apache.wicket.validation.validator.EmailAddressValidator; 023 024/** 025 * A {@link TextField} for HTML5 <input> with type <em>email</em>. 026 * 027 * <p> 028 * Automatically validates that the input is a valid email address. 029 * </p> 030 * <p> 031 * <strong>Note</strong>: This component does <strong>not</strong> support multiple values! That is 032 * <input type="email" multiple .../> cannot be validated with the default email 033 * validator 034 */ 035public class EmailTextField extends TextField<String> 036{ 037 private static final long serialVersionUID = 1L; 038 039 /** 040 * Construct. 041 * 042 * @param id 043 * component id 044 * @param emailAddress 045 * the email input value 046 */ 047 public EmailTextField(String id, final String emailAddress) 048 { 049 this(id, Model.of(emailAddress)); 050 } 051 052 /** 053 * Construct. 054 * 055 * <p>Use this constructor when the model will be provided by a parent component.</p> 056 * 057 * @param id 058 * component id 059 * @param emailValidator 060 * the validator that will check the correctness of the input value 061 */ 062 public EmailTextField(String id, final IValidator<String> emailValidator) 063 { 064 this(id, null, emailValidator); 065 } 066 067 /** 068 * Construct. 069 * 070 * @param id 071 * see Component 072 * @param model 073 * the model 074 */ 075 public EmailTextField(String id, IModel<String> model) 076 { 077 this(id, model, EmailAddressValidator.getInstance()); 078 } 079 080 /** 081 * Construct. 082 * 083 * <p>Use this constructor when the model will be provided by a parent component.</p> 084 * 085 * @param id 086 * see Component 087 */ 088 public EmailTextField(String id) 089 { 090 this(id, null, EmailAddressValidator.getInstance()); 091 } 092 093 /** 094 * Construct. 095 * 096 * @param id 097 * the component id 098 * @param model 099 * the input value 100 * @param emailValidator 101 * the validator that will check the correctness of the input value 102 */ 103 public EmailTextField(String id, IModel<String> model, IValidator<String> emailValidator) 104 { 105 super(id, model, String.class); 106 107 add(emailValidator); 108 } 109 110 @Override 111 protected String[] getInputTypes() 112 { 113 return new String[] {"email"}; 114 } 115}