1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.form; |
16 |
| |
17 |
| import org.apache.tapestry.IMarkupWriter; |
18 |
| import org.apache.tapestry.IRequestCycle; |
19 |
| import org.apache.tapestry.valid.ValidatorException; |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public abstract class TextField extends AbstractFormComponent implements TranslatedField |
32 |
| { |
33 |
| public abstract boolean isHidden(); |
34 |
| |
35 |
| public abstract Object getValue(); |
36 |
| public abstract void setValue(Object value); |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
5
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
42 |
| { |
43 |
5
| String value = getTranslatedFieldSupport().format(this, getValue());
|
44 |
| |
45 |
5
| renderDelegatePrefix(writer, cycle);
|
46 |
| |
47 |
5
| writer.beginEmpty("input");
|
48 |
| |
49 |
5
| writer.attribute("type", isHidden() ? "password" : "text");
|
50 |
| |
51 |
5
| writer.attribute("name", getName());
|
52 |
| |
53 |
5
| if (isDisabled())
|
54 |
1
| writer.attribute("disabled", "disabled");
|
55 |
| |
56 |
5
| if (value != null)
|
57 |
5
| writer.attribute("value", value);
|
58 |
| |
59 |
5
| renderIdAttribute(writer, cycle);
|
60 |
| |
61 |
5
| renderDelegateAttributes(writer, cycle);
|
62 |
| |
63 |
5
| getTranslatedFieldSupport().renderContributions(this, writer, cycle);
|
64 |
5
| getValidatableFieldSupport().renderContributions(this, writer, cycle);
|
65 |
| |
66 |
5
| renderInformalParameters(writer, cycle);
|
67 |
| |
68 |
5
| writer.closeTag();
|
69 |
| |
70 |
5
| renderDelegateSuffix(writer, cycle);
|
71 |
| } |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
3
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
77 |
| { |
78 |
3
| String value = cycle.getParameter(getName());
|
79 |
| |
80 |
3
| try
|
81 |
| { |
82 |
3
| Object object = getTranslatedFieldSupport().parse(this, value);
|
83 |
| |
84 |
2
| getValidatableFieldSupport().validate(this, writer, cycle, object);
|
85 |
| |
86 |
1
| setValue(object);
|
87 |
| } |
88 |
| catch (ValidatorException e) |
89 |
| { |
90 |
2
| getForm().getDelegate().record(e);
|
91 |
| } |
92 |
| } |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| public abstract ValidatableFieldSupport getValidatableFieldSupport(); |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| public abstract TranslatedFieldSupport getTranslatedFieldSupport(); |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
1
| public boolean isRequired()
|
108 |
| { |
109 |
1
| return getValidatableFieldSupport().isRequired(this);
|
110 |
| } |
111 |
| } |