1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.components;
23
24 import java.util.LinkedHashMap;
25 import java.util.Map;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.struts2.views.annotations.StrutsTag;
31 import org.apache.struts2.views.annotations.StrutsTagAttribute;
32
33 import com.opensymphony.xwork2.util.ValueStack;
34 import com.opensymphony.xwork2.util.logging.Logger;
35 import com.opensymphony.xwork2.util.logging.LoggerFactory;
36
37 /***
38 * <!-- START SNIPPET: javadoc -->
39 *
40 * Create a option transfer select component which is basically two <select ...>
41 * tag with buttons in the middle of them allowing options in each of the
42 * <select ...> to be moved between themselves. Will auto-select all its
43 * elements upon its containing form submision.
44 *
45 * <!-- END SNIPPET: javadoc -->
46 *
47 * <p/>
48 *
49 *
50 * <!-- START SNIPPET: notice -->
51 *
52 * NOTE: The id and doubleId need not be supplied as they will generated provided
53 * that the optiontransferselect tag is being used in a form tag. The generated id
54 * and doubleId will be <form_id>_<optiontransferselect_doubleName> and
55 * <form_id>_<optiontransferselect_doubleName> respectively.
56 *
57 * <!-- END SNIPPET: notice -->
58 *
59 * <p/>
60 *
61 * <pre>
62 * <!-- START SNIPPET: example -->
63 *
64 * <-- minimum configuration -->
65 * <s:optiontransferselect
66 * label="Favourite Cartoons Characters"
67 * name="leftSideCartoonCharacters"
68 * list="{'Popeye', 'He-Man', 'Spiderman'}"
69 * doubleName="rightSideCartoonCharacters"
70 * doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
71 * />
72 *
73 * <-- possible configuration -->
74 * <s:optiontransferselect
75 * label="Favourite Cartoons Characters"
76 * name="leftSideCartoonCharacters"
77 * leftTitle="Left Title"
78 * rightTitle="Right Title"
79 * list="{'Popeye', 'He-Man', 'Spiderman'}"
80 * multiple="true"
81 * headerKey="headerKey"
82 * headerValue="--- Please Select ---"
83 * emptyOption="true"
84 * doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
85 * doubleName="rightSideCartoonCharacters"
86 * doubleHeaderKey="doubleHeaderKey"
87 * doubleHeaderValue="--- Please Select ---"
88 * doubleEmptyOption="true"
89 * doubleMultiple="true"
90 * />
91 *
92 * <!-- END SNIPPET: example -->
93 * </pre>
94 *
95 */
96 @StrutsTag(name="optiontransferselect", tldTagClass="org.apache.struts2.views.jsp.ui.OptionTransferSelectTag", description="Renders an input form")
97 public class OptionTransferSelect extends DoubleListUIBean {
98
99 private static final Logger LOG = LoggerFactory.getLogger(OptionTransferSelect.class);
100
101 private static final String TEMPLATE = "optiontransferselect";
102
103 protected String allowAddToLeft;
104 protected String allowAddToRight;
105 protected String allowAddAllToLeft;
106 protected String allowAddAllToRight;
107 protected String allowSelectAll;
108 protected String allowUpDownOnLeft;
109 protected String allowUpDownOnRight;
110
111 protected String leftTitle;
112 protected String rightTitle;
113
114 protected String buttonCssClass;
115 protected String buttonCssStyle;
116
117 protected String addToLeftLabel;
118 protected String addToRightLabel;
119 protected String addAllToLeftLabel;
120 protected String addAllToRightLabel;
121 protected String selectAllLabel;
122 protected String leftUpLabel;
123 protected String leftDownlabel;
124 protected String rightUpLabel;
125 protected String rightDownLabel;
126
127 protected String addToLeftOnclick;
128 protected String addToRightOnclick;
129 protected String addAllToLeftOnclick;
130 protected String addAllToRightOnclick;
131 protected String selectAllOnclick;
132 protected String upDownOnLeftOnclick;
133 protected String upDownOnRightOnclick;
134
135
136 public OptionTransferSelect(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
137 super(stack, request, response);
138 }
139
140 protected String getDefaultTemplate() {
141 return TEMPLATE;
142 }
143
144
145 public void evaluateExtraParams() {
146 super.evaluateExtraParams();
147
148 Object doubleValue = null;
149
150
151 if (doubleList != null) {
152 doubleValue = findValue(doubleList);
153 addParameter("doubleList", doubleValue);
154 }
155 if (size == null || size.trim().length() <= 0) {
156 addParameter("size", "15");
157 }
158 if (doubleSize == null || doubleSize.trim().length() <= 0) {
159 addParameter("doubleSize", "15");
160 }
161 if (multiple == null || multiple.trim().length() <= 0) {
162 addParameter("multiple", Boolean.TRUE);
163 }
164 if (doubleMultiple == null || doubleMultiple.trim().length() <= 0) {
165 addParameter("doubleMultiple", Boolean.TRUE);
166 }
167
168
169
170
171
172
173 if (buttonCssClass != null && buttonCssClass.trim().length() > 0) {
174 addParameter("buttonCssClass", buttonCssClass);
175 }
176
177
178 if (buttonCssStyle != null && buttonCssStyle.trim().length() > 0) {
179 addParameter("buttonCssStyle", buttonCssStyle);
180 }
181
182
183
184
185 addParameter("allowSelectAll",
186 allowSelectAll != null ? findValue(allowSelectAll, Boolean.class) : Boolean.TRUE);
187
188
189 addParameter("allowAddToLeft",
190 allowAddToLeft != null ? findValue(allowAddToLeft, Boolean.class) : Boolean.TRUE);
191
192
193 addParameter("allowAddToRight",
194 allowAddToRight != null ? findValue(allowAddToRight, Boolean.class) : Boolean.TRUE);
195
196
197 addParameter("allowAddAllToLeft",
198 allowAddAllToLeft != null ? findValue(allowAddAllToLeft, Boolean.class) : Boolean.TRUE);
199
200
201 addParameter("allowAddAllToRight",
202 allowAddAllToRight != null ? findValue(allowAddAllToRight, Boolean.class) : Boolean.TRUE);
203
204
205 addParameter("allowUpDownOnLeft",
206 allowUpDownOnLeft != null ? findValue(allowUpDownOnLeft, Boolean.class) : Boolean.TRUE);
207
208
209 addParameter("allowUpDownOnRight",
210 allowUpDownOnRight != null ? findValue(allowUpDownOnRight, Boolean.class) : Boolean.TRUE);
211
212
213
214 if (leftTitle != null) {
215 addParameter("leftTitle", findValue(leftTitle, String.class));
216 }
217
218
219 if (rightTitle != null) {
220 addParameter("rightTitle", findValue(rightTitle, String.class));
221 }
222
223
224
225 addParameter("addToLeftLabel",
226 addToLeftLabel != null ? findValue(addToLeftLabel, String.class) : "<-" );
227
228
229 addParameter("addToRightLabel",
230 addToRightLabel != null ? findValue(addToRightLabel, String.class) : "->");
231
232
233 addParameter("addAllToLeftLabel",
234 addAllToLeftLabel != null ? findValue(addAllToLeftLabel, String.class) : "<<--");
235
236
237 addParameter("addAllToRightLabel",
238 addAllToRightLabel != null ? findValue(addAllToRightLabel, String.class) : "-->>");
239
240
241 addParameter("selectAllLabel",
242 selectAllLabel != null ? findValue(selectAllLabel, String.class) : "<*>");
243
244
245 addParameter("leftUpLabel",
246 leftUpLabel != null ? findValue(leftUpLabel, String.class) : "^");
247
248
249
250 addParameter("leftDownLabel",
251 leftDownlabel != null ? findValue(leftDownlabel, String.class) : "v");
252
253
254
255 addParameter("rightUpLabel",
256 rightUpLabel != null ? findValue(rightUpLabel, String.class) : "^");
257
258
259
260 addParameter("rightDownLabel",
261 rightDownLabel != null ? findValue(rightDownLabel, String.class) : "v");
262
263
264
265 addParameter("selectAllOnclick",
266 selectAllOnclick != null ? findValue(selectAllOnclick, String.class) : "");
267
268
269 addParameter("addToLeftOnclick",
270 addToLeftOnclick != null ? findValue(addToLeftOnclick, String.class) : "");
271
272
273 addParameter("addToRightOnclick",
274 addToRightOnclick != null ? findValue(addToRightOnclick, String.class) : "");
275
276
277 addParameter("addAllToLeftOnclick",
278 addAllToLeftOnclick != null ? findValue(addAllToLeftOnclick, String.class) : "");
279
280
281 addParameter("addAllToRightOnclick",
282 addAllToRightOnclick != null ? findValue(addAllToRightOnclick, String.class) : "");
283
284
285 addParameter("upDownOnLeftOnclick",
286 upDownOnLeftOnclick != null ? findValue(upDownOnLeftOnclick, String.class) : "");
287
288
289 addParameter("upDownOnRightOnclick",
290 upDownOnRightOnclick != null ? findValue(upDownOnRightOnclick, String.class) : "");
291
292
293
294
295
296 Form formAncestor = (Form) findAncestor(Form.class);
297 if (formAncestor != null) {
298
299
300 enableAncestorFormCustomOnsubmit();
301
302
303
304 Map formOptiontransferselectIds = (Map) formAncestor.getParameters().get("optiontransferselectIds");
305 Map formOptiontransferselectDoubleIds = (Map) formAncestor.getParameters().get("optiontransferselectDoubleIds");
306
307
308 if (formOptiontransferselectIds == null) {
309 formOptiontransferselectIds = new LinkedHashMap();
310 }
311 if (formOptiontransferselectDoubleIds == null) {
312 formOptiontransferselectDoubleIds = new LinkedHashMap();
313 }
314
315
316
317 String tmpId = (String) getParameters().get("id");
318 String tmpHeaderKey = (String) getParameters().get("headerKey");
319 if (tmpId != null && (! formOptiontransferselectIds.containsKey(tmpId))) {
320 formOptiontransferselectIds.put(tmpId, tmpHeaderKey);
321 }
322
323
324 String tmpDoubleId = (String) getParameters().get("doubleId");
325 String tmpDoubleHeaderKey = (String) getParameters().get("doubleHeaderKey");
326 if (tmpDoubleId != null && (! formOptiontransferselectDoubleIds.containsKey(tmpDoubleId))) {
327 formOptiontransferselectDoubleIds.put(tmpDoubleId, tmpDoubleHeaderKey);
328 }
329
330 formAncestor.getParameters().put("optiontransferselectIds", formOptiontransferselectIds);
331 formAncestor.getParameters().put("optiontransferselectDoubleIds", formOptiontransferselectDoubleIds);
332
333 }
334 else {
335 LOG.warn("form enclosing optiontransferselect "+this+" not found, auto select upon form submit of optiontransferselect will not work");
336 }
337 }
338
339
340
341 public String getAddAllToLeftLabel() {
342 return addAllToLeftLabel;
343 }
344
345 @StrutsTagAttribute(description="Set Add To Left button label")
346 public void setAddAllToLeftLabel(String addAllToLeftLabel) {
347 this.addAllToLeftLabel = addAllToLeftLabel;
348 }
349
350 public String getAddAllToRightLabel() {
351 return addAllToRightLabel;
352 }
353
354 @StrutsTagAttribute(description="Set Add All To Right button label")
355 public void setAddAllToRightLabel(String addAllToRightLabel) {
356 this.addAllToRightLabel = addAllToRightLabel;
357 }
358
359 public String getAddToLeftLabel() {
360 return addToLeftLabel;
361 }
362
363 @StrutsTagAttribute(description="Set Add To Left button label")
364 public void setAddToLeftLabel(String addToLeftLabel) {
365 this.addToLeftLabel = addToLeftLabel;
366 }
367
368 public String getAddToRightLabel() {
369 return addToRightLabel;
370 }
371
372 @StrutsTagAttribute(description="Set Add To Right button label")
373 public void setAddToRightLabel(String addToRightLabel) {
374 this.addToRightLabel = addToRightLabel;
375 }
376
377 public String getAllowAddAllToLeft() {
378 return allowAddAllToLeft;
379 }
380
381 @StrutsTagAttribute(description="Enable Add All To Left button")
382 public void setAllowAddAllToLeft(String allowAddAllToLeft) {
383 this.allowAddAllToLeft = allowAddAllToLeft;
384 }
385
386 public String getAllowAddAllToRight() {
387 return allowAddAllToRight;
388 }
389
390 @StrutsTagAttribute(description="Enable Add All To Right button")
391 public void setAllowAddAllToRight(String allowAddAllToRight) {
392 this.allowAddAllToRight = allowAddAllToRight;
393 }
394
395 public String getAllowAddToLeft() {
396 return allowAddToLeft;
397 }
398
399 @StrutsTagAttribute(description="Enable Add To Left button")
400 public void setAllowAddToLeft(String allowAddToLeft) {
401 this.allowAddToLeft = allowAddToLeft;
402 }
403
404 public String getAllowAddToRight() {
405 return allowAddToRight;
406 }
407
408 @StrutsTagAttribute(description="Enable Add To Right button")
409 public void setAllowAddToRight(String allowAddToRight) {
410 this.allowAddToRight = allowAddToRight;
411 }
412
413 public String getLeftTitle() {
414 return leftTitle;
415 }
416
417 @StrutsTagAttribute(description="Enable up / down on the left side")
418 public void setAllowUpDownOnLeft(String allowUpDownOnLeft) {
419 this.allowUpDownOnLeft = allowUpDownOnLeft;
420 }
421
422 public String getAllowUpDownOnLeft() {
423 return this.allowUpDownOnLeft;
424 }
425
426 @StrutsTagAttribute(description="Enable up / down on the right side")
427 public void setAllowUpDownOnRight(String allowUpDownOnRight) {
428 this.allowUpDownOnRight = allowUpDownOnRight;
429 }
430
431 public String getAllowUpDownOnRight() {
432 return this.allowUpDownOnRight;
433 }
434
435 @StrutsTagAttribute(description="Set Left title")
436 public void setLeftTitle(String leftTitle) {
437 this.leftTitle = leftTitle;
438 }
439
440 public String getRightTitle() {
441 return rightTitle;
442 }
443
444 @StrutsTagAttribute(description="Set Right title")
445 public void setRightTitle(String rightTitle) {
446 this.rightTitle = rightTitle;
447 }
448
449 @StrutsTagAttribute(description="Enable Select All button")
450 public void setAllowSelectAll(String allowSelectAll) {
451 this.allowSelectAll = allowSelectAll;
452 }
453
454 public String getAllowSelectAll() {
455 return this.allowSelectAll;
456 }
457
458 @StrutsTagAttribute(description="Set Select All button label")
459 public void setSelectAllLabel(String selectAllLabel) {
460 this.selectAllLabel = selectAllLabel;
461 }
462
463 public String getSelectAllLabel() {
464 return this.selectAllLabel;
465 }
466
467 @StrutsTagAttribute(description="Set buttons css class")
468 public void setButtonCssClass(String buttonCssClass) {
469 this.buttonCssClass = buttonCssClass;
470 }
471
472 public String getButtonCssClass() {
473 return buttonCssClass;
474 }
475
476 @StrutsTagAttribute(description="Set button css style")
477 public void setButtonCssStyle(String buttonCssStyle) {
478 this.buttonCssStyle = buttonCssStyle;
479 }
480
481 public String getButtonCssStyle() {
482 return this.buttonCssStyle;
483 }
484
485 @StrutsTagAttribute(description="Up label for the left side")
486 public void setLeftUpLabel(String leftUpLabel) {
487 this.leftUpLabel = leftUpLabel;
488 }
489 public String getLeftUpLabel() {
490 return this.leftUpLabel;
491 }
492
493 @StrutsTagAttribute(description="Down label for the left side.")
494 public void setLeftDownLabel(String leftDownLabel) {
495 this.leftDownlabel = leftDownLabel;
496 }
497 public String getLeftDownLabel() {
498 return this.leftDownlabel;
499 }
500
501 @StrutsTagAttribute(description="Up label for the right side.")
502 public void setRightUpLabel(String rightUpLabel) {
503 this.rightUpLabel = rightUpLabel;
504 }
505 public String getRightUpLabel() {
506 return this.rightUpLabel;
507 }
508
509 @StrutsTagAttribute(description="Down label for the left side.")
510 public void setRightDownLabel(String rightDownlabel) {
511 this.rightDownLabel = rightDownlabel;
512 }
513 public String getRightDownLabel() {
514 return rightDownLabel;
515 }
516
517 public String getAddAllToLeftOnclick() {
518 return addAllToLeftOnclick;
519 }
520
521 @StrutsTagAttribute(description="Javascript to run after Add All To Left button pressed")
522 public void setAddAllToLeftOnclick(String addAllToLeftOnclick) {
523 this.addAllToLeftOnclick = addAllToLeftOnclick;
524 }
525
526 public String getAddAllToRightOnclick() {
527 return addAllToRightOnclick;
528 }
529
530 @StrutsTagAttribute(description="Javascript to run after Add All To Right button pressed")
531 public void setAddAllToRightOnclick(String addAllToRightOnclick) {
532 this.addAllToRightOnclick = addAllToRightOnclick;
533 }
534
535 public String getAddToLeftOnclick() {
536 return addToLeftOnclick;
537 }
538
539 @StrutsTagAttribute(description="Javascript to run after Add To Left button pressed")
540 public void setAddToLeftOnclick(String addToLeftOnclick) {
541 this.addToLeftOnclick = addToLeftOnclick;
542 }
543
544 public String getAddToRightOnclick() {
545 return addToRightOnclick;
546 }
547
548 @StrutsTagAttribute(description="Javascript to run after Add To Right button pressed")
549 public void setAddToRightOnclick(String addToRightOnclick) {
550 this.addToRightOnclick = addToRightOnclick;
551 }
552
553 @StrutsTagAttribute(description="Javascript to run after up / down on the left side buttons pressed")
554 public void setUpDownOnLeftOnclick(String upDownOnLeftOnclick) {
555 this.upDownOnLeftOnclick = upDownOnLeftOnclick;
556 }
557
558 public String getUpDownOnLeftOnclick() {
559 return this.upDownOnLeftOnclick;
560 }
561
562 @StrutsTagAttribute(description="Javascript to run after up / down on the right side buttons pressed")
563 public void setUpDownOnRightOnclick(String upDownOnRightOnclick) {
564 this.upDownOnRightOnclick = upDownOnRightOnclick;
565 }
566
567 public String getUpDownOnRightOnclick() {
568 return this.upDownOnRightOnclick;
569 }
570
571 @StrutsTagAttribute(description="Javascript to run after Select All button pressed")
572 public void setSelectAllOnclick(String selectAllOnclick) {
573 this.selectAllOnclick = selectAllOnclick;
574 }
575
576 public String getSelectAllOnclick() {
577 return this.selectAllOnclick;
578 }
579
580 }