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.AbstractComponent; |
18 |
| import org.apache.tapestry.IForm; |
19 |
| import org.apache.tapestry.IMarkupWriter; |
20 |
| import org.apache.tapestry.IRequestCycle; |
21 |
| import org.apache.tapestry.PageRenderSupport; |
22 |
| import org.apache.tapestry.TapestryUtils; |
23 |
| import org.apache.tapestry.valid.IValidationDelegate; |
24 |
| import org.apache.tapestry.valid.ValidationConstants; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| public abstract class AbstractFormComponent extends AbstractComponent implements IFormComponent |
35 |
| { |
36 |
| private static final String SELECTED_ATTRIBUTE_NAME = "org.apache.tapestry.form.SelectedField"; |
37 |
| |
38 |
| public abstract IForm getForm(); |
39 |
| |
40 |
| public abstract void setForm(IForm form); |
41 |
| |
42 |
| public abstract String getName(); |
43 |
| |
44 |
| public abstract void setName(String name); |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| public abstract String getIdParameter(); |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| public abstract void setClientId(String id); |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
36
| protected void renderIdAttribute(IMarkupWriter writer, IRequestCycle cycle)
|
66 |
| { |
67 |
| |
68 |
| |
69 |
| |
70 |
36
| String rawId = getIdParameter();
|
71 |
| |
72 |
36
| if (rawId == null)
|
73 |
22
| return;
|
74 |
| |
75 |
14
| String id = cycle.getUniqueId(rawId);
|
76 |
| |
77 |
| |
78 |
| |
79 |
14
| setClientId(id);
|
80 |
| |
81 |
14
| writer.attribute("id", id);
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
108
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
89 |
| { |
90 |
108
| IForm form = TapestryUtils.getForm(cycle, this);
|
91 |
| |
92 |
107
| setForm(form);
|
93 |
| |
94 |
107
| if (form.wasPrerendered(writer, this))
|
95 |
5
| return;
|
96 |
| |
97 |
102
| IValidationDelegate delegate = form.getDelegate();
|
98 |
| |
99 |
102
| delegate.setFormComponent(this);
|
100 |
| |
101 |
102
| setName(form);
|
102 |
| |
103 |
101
| if (form.isRewinding())
|
104 |
| { |
105 |
42
| if (!isDisabled())
|
106 |
| { |
107 |
36
| rewindFormComponent(writer, cycle);
|
108 |
| } |
109 |
| } |
110 |
59
| else if (!cycle.isRewinding())
|
111 |
| { |
112 |
52
| if (!isDisabled())
|
113 |
45
| delegate.registerForFocus(this, ValidationConstants.NORMAL_FIELD);
|
114 |
| |
115 |
52
| renderFormComponent(writer, cycle);
|
116 |
| |
117 |
50
| if (delegate.isInError())
|
118 |
1
| delegate.registerForFocus(this, ValidationConstants.ERROR_FIELD);
|
119 |
| } |
120 |
| } |
121 |
| |
122 |
22
| protected void renderDelegatePrefix(IMarkupWriter writer, IRequestCycle cycle)
|
123 |
| { |
124 |
22
| getForm().getDelegate().writePrefix(writer, cycle, this, null);
|
125 |
| } |
126 |
| |
127 |
22
| protected void renderDelegateAttributes(IMarkupWriter writer, IRequestCycle cycle)
|
128 |
| { |
129 |
22
| getForm().getDelegate().writeAttributes(writer, cycle, this, null);
|
130 |
| } |
131 |
| |
132 |
21
| protected void renderDelegateSuffix(IMarkupWriter writer, IRequestCycle cycle)
|
133 |
| { |
134 |
21
| getForm().getDelegate().writeSuffix(writer, cycle, this, null);
|
135 |
| } |
136 |
| |
137 |
94
| protected void setName(IForm form)
|
138 |
| { |
139 |
94
| form.getElementId(this);
|
140 |
| } |
141 |
| |
142 |
| protected abstract void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle); |
143 |
| |
144 |
| protected abstract void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle); |
145 |
| } |