001 // Copyright 2006, 2007, 2008, 2011 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.corelib.components;
016
017 import org.apache.tapestry5.BindingConstants;
018 import org.apache.tapestry5.MarkupWriter;
019 import org.apache.tapestry5.annotations.Parameter;
020 import org.apache.tapestry5.corelib.base.AbstractTextField;
021
022 /**
023 * TextField component corresponds to {@code <input>} element. The value parameter will be edited (read when the containing
024 * {@link Form} is rendered, and updated when the form is submitted). TextField
025 * is generally used with string values, but other values are acceptable, as long as they can be freely converted back
026 * and forth to strings.
027 * <p/>
028 * Includes the <code>size</code> attribute, if a {@link org.apache.tapestry5.beaneditor.Width} annotation is present on
029 * the property bound to the value parameter.
030 *
031 * @tapestrydoc
032 */
033 public class TextField extends AbstractTextField
034 {
035 /**
036 * Sets the type attribute of the {@code <input>} element. The default is "text", but this can be overriden
037 * when using <a href="http://www.w3.org/TR/html5/the-input-element.html">HTML5</a> types such as "number".
038 */
039 @Parameter(allowNull = false, value = "text", defaultPrefix = BindingConstants.LITERAL)
040 private String type;
041
042 @Override
043 protected void writeFieldTag(MarkupWriter writer, String value)
044 {
045 writer.element("input",
046
047 "type", type,
048
049 "name", getControlName(),
050
051 "id", getClientId(),
052
053 "value", value,
054
055 "size", getWidth());
056 }
057
058 final void afterRender(MarkupWriter writer)
059 {
060 writer.end(); // input
061 }
062
063 }