KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > TextField


1 // Copyright 2004, 2005 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.tapestry.form;
16
17 import org.apache.tapestry.IBinding;
18 import org.apache.tapestry.IMarkupWriter;
19 import org.apache.tapestry.IRequestCycle;
20
21 /**
22  * Implements a component that manages an HTML <input type=text> or <input
23  * type=password> form element.
24  * [ <a HREF="../../../../../ComponentReference/TextField.html">Component Reference </a>]
25  *
26  * As of 4.0, TextField can indicate that it is required, use a custom translator
27  * (e.g. for numbers, dates, etc), and perform validation on the submitted value.
28  *
29  * @author Howard Lewis Ship
30  * @author Paul Ferraro
31  */

32 public abstract class TextField extends AbstractValidatableField
33 {
34     public abstract boolean isHidden();
35     
36     public abstract Object JavaDoc getValue();
37     
38     public abstract void setValue(Object JavaDoc value);
39     
40     /**
41      * @see org.apache.tapestry.form.validator.AbstractValidatableField#render(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle, java.lang.String)
42      */

43     public void render(IMarkupWriter writer, IRequestCycle cycle, String JavaDoc value)
44     {
45         renderDelegatePrefix(writer, cycle);
46         
47         writer.beginEmpty("input");
48
49         writer.attribute("type", isHidden() ? "password" : "text");
50
51         writer.attribute("name", getName());
52
53         if (isDisabled())
54             writer.attribute("disabled", "disabled");
55
56         if (value != null)
57             writer.attribute("value", value);
58
59         renderIdAttribute(writer, cycle);
60
61         renderDelegateAttributes(writer, cycle);
62         
63         renderContributions(writer, cycle);
64         
65         renderInformalParameters(writer, cycle);
66
67         writer.closeTag();
68         
69         renderDelegateSuffix(writer, cycle);
70     }
71     
72     /**
73      * @see org.apache.tapestry.form.ValidatableField#writeValue(java.lang.Object)
74      */

75     public void writeValue(Object JavaDoc value)
76     {
77         setValue(value);
78     }
79     
80     /**
81      * @see org.apache.tapestry.form.ValidatableField#readValue()
82      */

83     public Object JavaDoc readValue()
84     {
85         return getValue();
86     }
87 }
Popular Tags