1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.form; |
16 |
|
|
17 |
|
import java.util.Iterator; |
18 |
|
|
19 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
20 |
|
import org.apache.tapestry.IActionListener; |
21 |
|
import org.apache.tapestry.IForm; |
22 |
|
import org.apache.tapestry.IMarkupWriter; |
23 |
|
import org.apache.tapestry.IRequestCycle; |
24 |
|
import org.apache.tapestry.Tapestry; |
25 |
|
import org.apache.tapestry.coerce.ValueConverter; |
26 |
|
import org.apache.tapestry.listener.ListenerInvoker; |
27 |
|
import org.apache.tapestry.services.DataSqueezer; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
0 |
public abstract class ListEdit extends AbstractFormComponent |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
46 |
|
{ |
47 |
0 |
this.render(writer, cycle, getSource()); |
48 |
0 |
} |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
55 |
|
{ |
56 |
0 |
String[] values = cycle.getParameters(getName()); |
57 |
|
|
58 |
0 |
this.render(writer, cycle, (Iterator) getValueConverter().coerceValue( |
59 |
|
values, |
60 |
0 |
Iterator.class)); |
61 |
0 |
} |
62 |
|
|
63 |
|
protected void render(IMarkupWriter writer, IRequestCycle cycle, Iterator i) |
64 |
|
{ |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
0 |
if (i == null) |
70 |
0 |
return; |
71 |
|
|
72 |
0 |
int index = 0; |
73 |
|
|
74 |
0 |
String element = getElement(); |
75 |
|
|
76 |
0 |
boolean indexBound = isParameterBound("index"); |
77 |
|
|
78 |
0 |
while (i.hasNext()) |
79 |
|
{ |
80 |
0 |
Object value = null; |
81 |
|
|
82 |
0 |
if (indexBound) |
83 |
0 |
setIndex(index++); |
84 |
|
|
85 |
0 |
if (cycle.isRewinding()) |
86 |
0 |
value = convertValue((String) i.next()); |
87 |
|
else |
88 |
|
{ |
89 |
0 |
value = i.next(); |
90 |
0 |
writeValue(getForm(), getName(), value); |
91 |
|
} |
92 |
|
|
93 |
0 |
setValue(value); |
94 |
|
|
95 |
0 |
getListenerInvoker().invokeListener(getListener(), this, cycle); |
96 |
|
|
97 |
0 |
if (element != null) |
98 |
|
{ |
99 |
0 |
writer.begin(element); |
100 |
0 |
renderInformalParameters(writer, cycle); |
101 |
|
} |
102 |
|
|
103 |
0 |
renderBody(writer, cycle); |
104 |
|
|
105 |
0 |
if (element != null) |
106 |
0 |
writer.end(); |
107 |
0 |
} |
108 |
0 |
} |
109 |
|
|
110 |
|
private void writeValue(IForm form, String name, Object value) |
111 |
|
{ |
112 |
|
String externalValue; |
113 |
|
|
114 |
|
try |
115 |
|
{ |
116 |
0 |
externalValue = getDataSqueezer().squeeze(value); |
117 |
|
} |
118 |
0 |
catch (Exception ex) |
119 |
|
{ |
120 |
0 |
throw new ApplicationRuntimeException(Tapestry.format( |
121 |
|
"ListEdit.unable-to-convert-value", |
122 |
|
value), this, null, ex); |
123 |
0 |
} |
124 |
|
|
125 |
0 |
form.addHiddenValue(name, externalValue); |
126 |
0 |
} |
127 |
|
|
128 |
|
private Object convertValue(String value) |
129 |
|
{ |
130 |
|
try |
131 |
|
{ |
132 |
0 |
return getDataSqueezer().unsqueeze(value); |
133 |
|
} |
134 |
0 |
catch (Exception ex) |
135 |
|
{ |
136 |
0 |
throw new ApplicationRuntimeException(Tapestry.format( |
137 |
|
"ListEdit.unable-to-convert-string", |
138 |
|
value), this, null, ex); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
public abstract String getElement(); |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
public abstract IActionListener getListener(); |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
public boolean isDisabled() |
151 |
|
{ |
152 |
0 |
return false; |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
public abstract Iterator getSource(); |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
public abstract void setValue(Object value); |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
public abstract void setIndex(int index); |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
public abstract DataSqueezer getDataSqueezer(); |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
public abstract ValueConverter getValueConverter(); |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
public abstract ListenerInvoker getListenerInvoker(); |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
protected boolean getCanTakeFocus() |
189 |
|
{ |
190 |
0 |
return false; |
191 |
|
} |
192 |
|
|
193 |
|
public String getDisplayName() |
194 |
|
{ |
195 |
|
|
196 |
0 |
return null; |
197 |
|
} |
198 |
|
|
199 |
|
} |