1 // Copyright 2006, 2007, 2008 The Apache Software Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package org.apache.tapestry5;
16
17 /**
18 * Defines a field within a form. Fields have a <a href="http://www.w3.org/TR/html4/interact/forms.html#control-name">control
19 * name</a> that is used when rendering and, later, when the form is submitted, to identify the query parameter.
20 * <p/>
21 * Timing is important, as components may render multiple times, due to looping and other factors. Generally, a
22 * component's {@link #getControlName()} will only be accurate after it has rendered. In some cases, when generating
23 * JavaScript for example, it is necessary to {@linkplain org.apache.tapestry5.services.Heartbeat#defer(Runnable) wait
24 * until the end of the current Heartbeat} to ensure that all components have had thier chance to render.
25 */
26 public interface Field extends ClientElement
27 {
28 /**
29 * Returns the value used as the name attribute of the rendered element. This value will be unique within an
30 * enclosing form, even if the same component renders multiple times.
31 *
32 * @see org.apache.tapestry5.services.FormSupport#allocateControlName(String)
33 */
34 String getControlName();
35
36 /**
37 * Returns a user presentable (localized) label for the field, which may be used inside <label> elements on
38 * the client, and inside client or server-side validation error messages.
39 *
40 * @return the label
41 * @see org.apache.tapestry5.corelib.components.Label
42 */
43 String getLabel();
44
45 /**
46 * Returns true if the field is disabled; A disabled field will render a disabled attribute so that it is
47 * non-responsive on the client (at least, until its disabled status is changed on the client using JavaScript). A
48 * disabled field will ignore any value passed up in a form submit request. Care must be taken if the disabled
49 * status of a field can change between the time the field is rendered and the time the enclosing form is
50 * submitted.
51 */
52 boolean isDisabled();
53
54 /**
55 * Returns true if this field required (as per {@link org.apache.tapestry5.FieldValidator#isRequired()}).
56 *
57 * @return true if a non-blank value is required for the field
58 */
59 boolean isRequired();
60 }