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