|
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 |
15
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
42 |
| { |
|
43 |
15
| String value = getTranslatedFieldSupport().format(this, getValue());
|
|
44 |
| |
|
45 |
15
| renderDelegatePrefix(writer, cycle);
|
|
46 |
| |
|
47 |
15
| writer.beginEmpty("input");
|
|
48 |
| |
|
49 |
15
| writer.attribute("type", isHidden() ? "password" : "text");
|
|
50 |
| |
|
51 |
15
| writer.attribute("name", getName());
|
|
52 |
| |
|
53 |
15
| if (isDisabled())
|
|
54 |
3
| writer.attribute("disabled", "disabled");
|
|
55 |
| |
|
56 |
15
| if (value != null)
|
|
57 |
15
| writer.attribute("value", value);
|
|
58 |
| |
|
59 |
15
| renderIdAttribute(writer, cycle);
|
|
60 |
| |
|
61 |
15
| renderDelegateAttributes(writer, cycle);
|
|
62 |
| |
|
63 |
15
| getTranslatedFieldSupport().renderContributions(this, writer, cycle);
|
|
64 |
15
| getValidatableFieldSupport().renderContributions(this, writer, cycle);
|
|
65 |
| |
|
66 |
15
| renderInformalParameters(writer, cycle);
|
|
67 |
| |
|
68 |
15
| writer.closeTag();
|
|
69 |
| |
|
70 |
15
| renderDelegateSuffix(writer, cycle);
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
9
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
77 |
| { |
|
78 |
9
| String value = cycle.getParameter(getName());
|
|
79 |
| |
|
80 |
9
| try
|
|
81 |
| { |
|
82 |
9
| Object object = getTranslatedFieldSupport().parse(this, value);
|
|
83 |
| |
|
84 |
6
| getValidatableFieldSupport().validate(this, writer, cycle, object);
|
|
85 |
| |
|
86 |
3
| setValue(object);
|
|
87 |
| } |
|
88 |
| catch (ValidatorException e) |
|
89 |
| { |
|
90 |
6
| 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 |
3
| public boolean isRequired()
|
|
108 |
| { |
|
109 |
3
| return getValidatableFieldSupport().isRequired(this);
|
|
110 |
| } |
|
111 |
| } |