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