001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5; 014 015/** 016 * Defines a field within a form. Fields have a <a href="http://www.w3.org/TR/html4/interact/forms.html#control-name">control 017 * name</a> that is used when rendering and, later, when the form is submitted, to identify the query parameter. 018 * <p/> 019 * Timing is important, as components may render multiple times, due to looping and other factors. Generally, a 020 * component's {@link #getControlName()} will only be accurate after it has rendered. In some cases, when generating 021 * JavaScript for example, it is necessary to {@linkplain org.apache.tapestry5.services.Heartbeat#defer(Runnable) wait 022 * until the end of the current Heartbeat} to ensure that all components have had their chance to render. 023 * <p/> 024 * Most Fields also implement {@link org.apache.tapestry5.Field2}, which was introduced to bridge a gap related to 025 * re-rendering a form as part of an Ajax request. 026 */ 027public interface Field extends ClientElement 028{ 029 /** 030 * Returns the value used as the name attribute of the rendered element. This value will be unique within an 031 * enclosing form, even if the same component renders multiple times. 032 * 033 * @see org.apache.tapestry5.services.FormSupport#allocateControlName(String) 034 */ 035 String getControlName(); 036 037 /** 038 * Returns a user presentable (localized) label for the field, which may be used inside <label> elements on 039 * the client, and inside client or server-side validation error messages. 040 * 041 * @return the label 042 * @see org.apache.tapestry5.corelib.components.Label 043 */ 044 String getLabel(); 045 046 /** 047 * Returns true if the field is disabled; A disabled field will render a disabled attribute so that it is 048 * non-responsive on the client (at least, until its disabled status is changed on the client using JavaScript). A 049 * disabled field will ignore any value passed up in a form submit request. Care must be taken if the disabled 050 * status of a field can change between the time the field is rendered and the time the enclosing form is 051 * submitted. 052 */ 053 boolean isDisabled(); 054 055 /** 056 * Returns true if this field required (as per {@link org.apache.tapestry5.FieldValidator#isRequired()}). 057 * 058 * @return true if a non-blank value is required for the field 059 */ 060 boolean isRequired(); 061}