001/* 002 * Copyright 2002-2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet.tags.form; 018 019import javax.servlet.jsp.JspException; 020 021/** 022 * Base class for databinding-aware JSP tags that render HTML form input element. 023 * 024 * <p>Provides a set of properties corresponding to the set of HTML attributes 025 * that are common across form input elements. 026 * 027 * @author Rob Harrop 028 * @author Rick Evans 029 * @author Juergen Hoeller 030 * @since 2.0 031 */ 032@SuppressWarnings("serial") 033public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag { 034 035 /** 036 * The name of the '{@code onfocus}' attribute. 037 */ 038 public static final String ONFOCUS_ATTRIBUTE = "onfocus"; 039 040 /** 041 * The name of the '{@code onblur}' attribute. 042 */ 043 public static final String ONBLUR_ATTRIBUTE = "onblur"; 044 045 /** 046 * The name of the '{@code onchange}' attribute. 047 */ 048 public static final String ONCHANGE_ATTRIBUTE = "onchange"; 049 050 /** 051 * The name of the '{@code accesskey}' attribute. 052 */ 053 public static final String ACCESSKEY_ATTRIBUTE = "accesskey"; 054 055 /** 056 * The name of the '{@code disabled}' attribute. 057 */ 058 public static final String DISABLED_ATTRIBUTE = "disabled"; 059 060 /** 061 * The name of the '{@code readonly}' attribute. 062 */ 063 public static final String READONLY_ATTRIBUTE = "readonly"; 064 065 066 private String onfocus; 067 068 private String onblur; 069 070 private String onchange; 071 072 private String accesskey; 073 074 private boolean disabled; 075 076 private boolean readonly; 077 078 079 /** 080 * Set the value of the '{@code onfocus}' attribute. 081 * May be a runtime expression. 082 */ 083 public void setOnfocus(String onfocus) { 084 this.onfocus = onfocus; 085 } 086 087 /** 088 * Get the value of the '{@code onfocus}' attribute. 089 */ 090 protected String getOnfocus() { 091 return this.onfocus; 092 } 093 094 /** 095 * Set the value of the '{@code onblur}' attribute. 096 * May be a runtime expression. 097 */ 098 public void setOnblur(String onblur) { 099 this.onblur = onblur; 100 } 101 102 /** 103 * Get the value of the '{@code onblur}' attribute. 104 */ 105 protected String getOnblur() { 106 return this.onblur; 107 } 108 109 /** 110 * Set the value of the '{@code onchange}' attribute. 111 * May be a runtime expression. 112 */ 113 public void setOnchange(String onchange) { 114 this.onchange = onchange; 115 } 116 117 /** 118 * Get the value of the '{@code onchange}' attribute. 119 */ 120 protected String getOnchange() { 121 return this.onchange; 122 } 123 124 /** 125 * Set the value of the '{@code accesskey}' attribute. 126 * May be a runtime expression. 127 */ 128 public void setAccesskey(String accesskey) { 129 this.accesskey = accesskey; 130 } 131 132 /** 133 * Get the value of the '{@code accesskey}' attribute. 134 */ 135 protected String getAccesskey() { 136 return this.accesskey; 137 } 138 139 /** 140 * Set the value of the '{@code disabled}' attribute. 141 */ 142 public void setDisabled(boolean disabled) { 143 this.disabled = disabled; 144 } 145 146 /** 147 * Get the value of the '{@code disabled}' attribute. 148 */ 149 protected boolean isDisabled() { 150 return this.disabled; 151 } 152 153 /** 154 * Sets the value of the '{@code readonly}' attribute. 155 */ 156 public void setReadonly(boolean readonly) { 157 this.readonly = readonly; 158 } 159 160 /** 161 * Gets the value of the '{@code readonly}' attribute. 162 */ 163 protected boolean isReadonly() { 164 return this.readonly; 165 } 166 167 168 /** 169 * Adds input-specific optional attributes as defined by this base class. 170 */ 171 @Override 172 protected void writeOptionalAttributes(TagWriter tagWriter) throws JspException { 173 super.writeOptionalAttributes(tagWriter); 174 175 writeOptionalAttribute(tagWriter, ONFOCUS_ATTRIBUTE, getOnfocus()); 176 writeOptionalAttribute(tagWriter, ONBLUR_ATTRIBUTE, getOnblur()); 177 writeOptionalAttribute(tagWriter, ONCHANGE_ATTRIBUTE, getOnchange()); 178 writeOptionalAttribute(tagWriter, ACCESSKEY_ATTRIBUTE, getAccesskey()); 179 if (isDisabled()) { 180 tagWriter.writeAttribute(DISABLED_ATTRIBUTE, "disabled"); 181 } 182 if (isReadonly()) { 183 writeOptionalAttribute(tagWriter, READONLY_ATTRIBUTE, "readonly"); 184 } 185 } 186 187}