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 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
7
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
43 |
| { |
44 |
7
| IForm form = TapestryUtils.getForm(cycle, this);
|
45 |
| |
46 |
7
| IFormComponent field = getField();
|
47 |
| |
48 |
7
| if (field != null)
|
49 |
4
| form.prerenderField(writer, field, getLocation());
|
50 |
| |
51 |
7
| if (cycle.isRewinding())
|
52 |
1
| return;
|
53 |
| |
54 |
6
| String displayName = getDisplayName();
|
55 |
| |
56 |
6
| if (displayName == null)
|
57 |
| { |
58 |
4
| if (field == null)
|
59 |
1
| throw Tapestry.createRequiredParameterException(this, "field");
|
60 |
| |
61 |
3
| displayName = field.getDisplayName();
|
62 |
| |
63 |
3
| if (displayName == null)
|
64 |
1
| throw new BindingException(ValidMessages.noDisplayName(this, field), this, null,
|
65 |
| getBinding("field"), null); |
66 |
| } |
67 |
| |
68 |
4
| IValidationDelegate delegate = form.getDelegate();
|
69 |
| |
70 |
4
| String id = field == null ? null : field.getClientId();
|
71 |
| |
72 |
4
| delegate.writeLabelPrefix(field, writer, cycle);
|
73 |
| |
74 |
4
| writer.begin("label");
|
75 |
| |
76 |
4
| if (id != null)
|
77 |
1
| writer.attribute("for", id);
|
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
4
| renderInformalParameters(writer, cycle);
|
83 |
| |
84 |
4
| writer.print(displayName, getRaw());
|
85 |
| |
86 |
4
| writer.end();
|
87 |
| |
88 |
4
| delegate.writeLabelSuffix(field, writer, cycle);
|
89 |
| } |
90 |
| |
91 |
| |
92 |
| public abstract String getDisplayName(); |
93 |
| |
94 |
| |
95 |
| public abstract IFormComponent getField(); |
96 |
| |
97 |
| |
98 |
| public abstract boolean getRaw(); |
99 |
| } |