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