|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.valid; |
|
16 |
| |
|
17 |
| import org.apache.tapestry.AbstractComponent; |
|
18 |
| import org.apache.tapestry.BindingException; |
|
19 |
| import org.apache.tapestry.IForm; |
|
20 |
| import org.apache.tapestry.IMarkupWriter; |
|
21 |
| import org.apache.tapestry.IRequestCycle; |
|
22 |
| import org.apache.tapestry.Tapestry; |
|
23 |
| import org.apache.tapestry.TapestryUtils; |
|
24 |
| import org.apache.tapestry.form.IFormComponent; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public abstract class FieldLabel extends AbstractComponent |
|
36 |
| { |
|
37 |
| |
|
38 |
| public abstract boolean isPrerender(); |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
24
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
46 |
| { |
|
47 |
24
| IForm form = TapestryUtils.getForm(cycle, this);
|
|
48 |
| |
|
49 |
24
| IFormComponent field = getField();
|
|
50 |
| |
|
51 |
24
| if (field != null && isPrerender())
|
|
52 |
12
| form.prerenderField(writer, field, getLocation());
|
|
53 |
| |
|
54 |
24
| if (cycle.isRewinding())
|
|
55 |
3
| return;
|
|
56 |
| |
|
57 |
21
| String displayName = getDisplayName();
|
|
58 |
| |
|
59 |
21
| if (displayName == null)
|
|
60 |
| { |
|
61 |
15
| if (field == null)
|
|
62 |
3
| throw Tapestry.createRequiredParameterException(this, "field");
|
|
63 |
| |
|
64 |
12
| displayName = field.getDisplayName();
|
|
65 |
| |
|
66 |
12
| if (displayName == null)
|
|
67 |
3
| throw new BindingException(ValidMessages.noDisplayName(this, field), this, null,
|
|
68 |
| getBinding("field"), null); |
|
69 |
| } |
|
70 |
| |
|
71 |
15
| IValidationDelegate delegate = form.getDelegate();
|
|
72 |
| |
|
73 |
15
| String id = field == null ? null : field.getClientId();
|
|
74 |
| |
|
75 |
15
| delegate.writeLabelPrefix(field, writer, cycle);
|
|
76 |
| |
|
77 |
15
| writer.begin("label");
|
|
78 |
| |
|
79 |
15
| if (id != null)
|
|
80 |
3
| writer.attribute("for", id);
|
|
81 |
| |
|
82 |
15
| delegate.writeLabelAttributes(writer, cycle, field);
|
|
83 |
15
| renderInformalParameters(writer, cycle);
|
|
84 |
| |
|
85 |
15
| writer.print(displayName, getRaw());
|
|
86 |
| |
|
87 |
15
| writer.end();
|
|
88 |
| |
|
89 |
15
| delegate.writeLabelSuffix(field, writer, cycle);
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| public abstract String getDisplayName(); |
|
94 |
| |
|
95 |
| |
|
96 |
| public abstract IFormComponent getField(); |
|
97 |
| |
|
98 |
| |
|
99 |
| public abstract boolean getRaw(); |
|
100 |
| } |