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 |
| public abstract class ListEdit extends AbstractFormComponent |
40 |
| { |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
3
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
46 |
| { |
47 |
3
| this.render(writer, cycle, getSource());
|
48 |
| } |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
2
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
55 |
| { |
56 |
2
| String[] values = cycle.getParameters(getName());
|
57 |
| |
58 |
2
| this.render(writer, cycle, (Iterator) getValueConverter().coerceValue(
|
59 |
| values, |
60 |
| Iterator.class)); |
61 |
| } |
62 |
| |
63 |
5
| protected void render(IMarkupWriter writer, IRequestCycle cycle, Iterator i)
|
64 |
| { |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
5
| if (i == null)
|
70 |
0
| return;
|
71 |
| |
72 |
5
| int index = 0;
|
73 |
| |
74 |
5
| String element = getElement();
|
75 |
| |
76 |
5
| boolean indexBound = isParameterBound("index");
|
77 |
| |
78 |
5
| while (i.hasNext())
|
79 |
| { |
80 |
10
| Object value = null;
|
81 |
| |
82 |
10
| if (indexBound)
|
83 |
3
| setIndex(index++);
|
84 |
| |
85 |
10
| if (cycle.isRewinding())
|
86 |
4
| value = convertValue((String) i.next());
|
87 |
| else |
88 |
| { |
89 |
6
| value = i.next();
|
90 |
6
| writeValue(getForm(), getName(), value);
|
91 |
| } |
92 |
| |
93 |
9
| setValue(value);
|
94 |
| |
95 |
9
| getListenerInvoker().invokeListener(getListener(), this, cycle);
|
96 |
| |
97 |
9
| if (element != null)
|
98 |
| { |
99 |
6
| writer.begin(element);
|
100 |
6
| renderInformalParameters(writer, cycle);
|
101 |
| } |
102 |
| |
103 |
9
| renderBody(writer, cycle);
|
104 |
| |
105 |
9
| if (element != null)
|
106 |
6
| writer.end();
|
107 |
| } |
108 |
| } |
109 |
| |
110 |
6
| private void writeValue(IForm form, String name, Object value)
|
111 |
| { |
112 |
6
| String externalValue;
|
113 |
| |
114 |
6
| try
|
115 |
| { |
116 |
6
| externalValue = getDataSqueezer().squeeze(value);
|
117 |
| } |
118 |
| catch (Exception ex) |
119 |
| { |
120 |
0
| throw new ApplicationRuntimeException(Tapestry.format(
|
121 |
| "ListEdit.unable-to-convert-value", |
122 |
| value), this, null, ex); |
123 |
| } |
124 |
| |
125 |
6
| form.addHiddenValue(name, externalValue);
|
126 |
| } |
127 |
| |
128 |
4
| private Object convertValue(String value)
|
129 |
| { |
130 |
4
| try
|
131 |
| { |
132 |
4
| return getDataSqueezer().unsqueeze(value);
|
133 |
| } |
134 |
| catch (Exception ex) |
135 |
| { |
136 |
1
| 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 |
0
| 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 |
3
| protected boolean getCanTakeFocus()
|
189 |
| { |
190 |
3
| return false;
|
191 |
| } |
192 |
| |
193 |
0
| public String getClientId()
|
194 |
| { |
195 |
| |
196 |
0
| return null;
|
197 |
| } |
198 |
| |
199 |
0
| public String getDisplayName()
|
200 |
| { |
201 |
| |
202 |
0
| return null;
|
203 |
| } |
204 |
| |
205 |
| } |