    001// Copyright 2006-2013 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
    015package org.apache.tapestry5.corelib.components;
    016
    017import org.apache.tapestry5.BindingConstants;
    018import org.apache.tapestry5.MarkupWriter;
    019import org.apache.tapestry5.annotations.Parameter;
    020import 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 */
    033public 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                       "class", cssClass,
    052
    053                       "id", getClientId(),
    054
    055                       "value", value,
    056
    057                       "size", getWidth());
    058    }
    059
    060    final void afterRender(MarkupWriter writer)
    061    {
    062        writer.end(); // input
    063    }
    064
    065}