View Javadoc

1   /*
2    * $Id: DoubleListUIBean.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.components;
19  
20  import java.util.Map;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import com.opensymphony.xwork2.util.ValueStack;
26  
27  /***
28   * DoubleListUIBean is the standard superclass of all Struts double list handling components.
29   *
30   * <p/>
31   *
32   * <!-- START SNIPPET: javadoc -->
33   * 
34   * Note that the doublelistkey and doublelistvalue attribute will default to "key" and "value"
35   * respectively only when the doublelist attribute is evaluated to a Map or its decendant.
36   * Other thing else, will result in doublelistkey and doublelistvalue to be null and not used.
37   * 
38   * <!-- END SNIPPET: javadoc -->
39   *
40   */
41  public abstract class DoubleListUIBean extends ListUIBean {
42  	
43  	protected String emptyOption;
44      protected String headerKey;
45      protected String headerValue;
46      protected String multiple;
47      protected String size;
48  	
49      protected String doubleList;
50      protected String doubleListKey;
51      protected String doubleListValue;
52      protected String doubleName;
53      protected String doubleValue;
54      protected String formName;
55      
56      protected String doubleId;
57      protected String doubleDisabled;
58      protected String doubleMultiple;
59      protected String doubleSize;
60      protected String doubleHeaderKey;
61      protected String doubleHeaderValue;
62      protected String doubleEmptyOption;
63      
64      protected String doubleCssClass;
65      protected String doubleCssStyle;
66      
67      protected String doubleOnclick;
68      protected String doubleOndblclick;
69      protected String doubleOnmousedown;
70      protected String doubleOnmouseup;
71      protected String doubleOnmouseover;
72      protected String doubleOnmousemove;
73      protected String doubleOnmouseout;
74      protected String doubleOnfocus;
75      protected String doubleOnblur;
76      protected String doubleOnkeypress;
77      protected String doubleOnkeydown;
78      protected String doubleOnkeyup;
79      protected String doubleOnselect;
80      protected String doubleOnchange;
81      
82      protected String doubleAccesskey;
83      
84  
85      public DoubleListUIBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
86          super(stack, request, response);
87      }
88  
89      public void evaluateExtraParams() {
90          super.evaluateExtraParams();
91  
92          //Object doubleName = null;
93          
94          if (emptyOption != null) {
95              addParameter("emptyOption", findValue(emptyOption, Boolean.class));
96          }
97  
98          if (multiple != null) {
99              addParameter("multiple", findValue(multiple, Boolean.class));
100         }
101 
102         if (size != null) {
103             addParameter("size", findString(size));
104         }
105 
106         if ((headerKey != null) && (headerValue != null)) {
107             addParameter("headerKey", findString(headerKey));
108             addParameter("headerValue", findString(headerValue));
109         }
110         
111         
112         if (doubleMultiple != null) {
113         	addParameter("doubleMultiple", findValue(doubleMultiple, Boolean.class));
114         }
115         
116         if (doubleSize != null) {
117         	addParameter("doubleSize", findString(doubleSize));
118         }
119         
120         if (doubleDisabled != null) {
121         	addParameter("doubleDisabled", findValue(doubleDisabled, Boolean.class));
122         }
123 
124         if (doubleName != null) {
125             addParameter("doubleName", findString(this.doubleName));
126         }
127 
128         if (doubleList != null) {
129             addParameter("doubleList", doubleList);
130         }
131         
132         Object tmpDoubleList = findValue(doubleList);
133         if (doubleListKey != null) {
134             addParameter("doubleListKey", doubleListKey);
135         }else if (tmpDoubleList instanceof Map) {
136         	addParameter("doubleListKey", "key");
137         }
138         
139         if (doubleListValue != null) {
140             if (altSyntax()) {
141                 // the same logic as with findValue(String)
142                 // if value start with %{ and end with }, just cut it off!
143                 if (doubleListValue.startsWith("%{") && doubleListValue.endsWith("}")) {
144                     doubleListValue = doubleListValue.substring(2, doubleListValue.length() - 1);
145                 }
146             }
147 
148             addParameter("doubleListValue", doubleListValue);
149         }else if (tmpDoubleList instanceof Map) {
150         	addParameter("doubleListValue", "value");
151         }
152 
153 
154         if (formName != null) {
155             addParameter("formName", findString(formName));
156         } else {
157             // ok, let's look it up
158             Component form = findAncestor(Form.class);
159             if (form != null) {
160                 addParameter("formName", form.getParameters().get("name"));
161             }
162         }
163 
164         Class valueClazz = getValueClassType();
165 
166         if (valueClazz != null) {
167             if (doubleValue != null) {
168                 addParameter("doubleNameValue", findValue(doubleValue, valueClazz));
169             } else if (doubleName != null) {
170                 addParameter("doubleNameValue", findValue(doubleName.toString(), valueClazz));
171             }
172         } else {
173             if (doubleValue != null) {
174                 addParameter("doubleNameValue", findValue(doubleValue));
175             } else if (doubleName != null) {
176                 addParameter("doubleNameValue", findValue(doubleName.toString()));
177             }
178         }
179         
180         Form form = (Form) findAncestor(Form.class);
181         if (doubleId != null) {
182             // this check is needed for backwards compatibility with 2.1.x
183             if (altSyntax()) {
184                 addParameter("doubleId", findString(doubleId));
185             } else {
186                 addParameter("doubleId", doubleId);
187             }
188         } else if (form != null) {
189             addParameter("doubleId", form.getParameters().get("id") + "_" +escape(this.doubleName));
190         }
191         
192         if (doubleOnclick != null) {
193         	addParameter("doubleOnclick", findString(doubleOnclick));
194         }
195         
196         if (doubleOndblclick != null) {
197         	addParameter("doubleOndblclick", findString(doubleOndblclick));
198         }
199         
200         if (doubleOnmousedown != null) {
201         	addParameter("doubleOnmousedown", findString(doubleOnmousedown));
202         }
203         
204         if (doubleOnmouseup != null) {
205         	addParameter("doubleOnmouseup", findString(doubleOnmouseup));
206         }
207         
208         if (doubleOnmouseover != null) {
209         	addParameter("doubleOnmouseover", findString(doubleOnmouseover));
210         }
211         
212         if (doubleOnmousemove != null) {
213         	addParameter("doubleOnmousemove", findString(doubleOnmousemove));
214         }
215         
216         if (doubleOnmouseout != null) {
217         	addParameter("doubleOnmouseout", findString(doubleOnmouseout));
218         }
219         
220         if (doubleOnfocus != null) {
221         	addParameter("doubleOnfocus", findString(doubleOnfocus));
222         }
223         
224         if (doubleOnblur != null) {
225         	addParameter("doubleOnblur", findString(doubleOnblur));
226         }
227         
228         if (doubleOnkeypress != null) {
229         	addParameter("doubleOnkeypress", findString(doubleOnkeypress));
230         }
231         
232         if (doubleOnkeydown != null) {
233         	addParameter("doubleOnkeydown", findString(doubleOnkeydown));
234         }
235         
236         if (doubleOnselect != null) {
237         	addParameter("doubleOnselect", findString(doubleOnselect));
238         }
239         
240         if (doubleOnchange != null) {
241         	addParameter("doubleOnchange", findString(doubleOnchange));
242         }
243         
244         if (doubleCssClass != null) {
245         	addParameter("doubleCss", findString(doubleCssClass));
246         }
247         
248         if (doubleCssStyle != null) {
249         	addParameter("doubleStyle", findString(doubleCssStyle));
250         }
251         
252         if (doubleHeaderKey != null && doubleHeaderValue != null) {
253         	addParameter("doubleHeaderKey", findString(doubleHeaderKey));
254         	addParameter("doubleHeaderValue", findString(doubleHeaderValue));
255         }
256         
257         if (doubleEmptyOption != null) {
258         	addParameter("doubleEmptyOption", findValue(doubleEmptyOption, Boolean.class));
259         }
260         
261         if (doubleAccesskey != null) {
262         	addParameter("doubleAccesskey", findString(doubleAccesskey));
263         }
264     }
265 
266     /***
267      * The second iterable source to populate from.
268      * @s.tagattribute required="true"
269      */
270     public void setDoubleList(String doubleList) {
271         this.doubleList = doubleList;
272     }
273 
274     /***
275      * The key expression to use for second list
276      * @s.tagattribute required="false"
277      */
278     public void setDoubleListKey(String doubleListKey) {
279         this.doubleListKey = doubleListKey;
280     }
281 
282     /***
283      * The value expression to use for second list
284      * @s.tagattribute required="false"
285      */
286     public void setDoubleListValue(String doubleListValue) {
287         this.doubleListValue = doubleListValue;
288     }
289 
290     /***
291      * The name for complete component
292      * @s.tagattribute required="true"
293      */
294     public void setDoubleName(String doubleName) {
295         this.doubleName = doubleName;
296     }
297 
298     /***
299      * The value expression for complete component
300      * @s.tagattribute required="false"
301      */
302     public void setDoubleValue(String doubleValue) {
303         this.doubleValue = doubleValue;
304     }
305 
306     /***
307      * The form name this component resides in and populates to
308      * @s.tagattribute required="false"
309      */
310     public void setFormName(String formName) {
311         this.formName = formName;
312     }
313     
314     public String getFormName() {
315     	return formName;
316     }
317     
318     /***
319      * The css class for the second list
320      * @s.tagattribute required="false"
321      */
322     public void setDoubleCssClass(String doubleCssClass) {
323     	this.doubleCssClass = doubleCssClass;
324     }
325     
326     public String getDoubleCssClass() {
327     	return doubleCssClass;
328     }
329     
330     /***
331      * The css style for the second list
332      * @s.tagattribute required="false"
333      */
334     public void setDoubleCssStyle(String doubleCssStyle) {
335     	this.doubleCssStyle = doubleCssStyle;
336     }
337     
338     public String getDoubleCssStyle() {
339     	return doubleCssStyle;
340     }
341     
342     /***
343      * The header key for the second list
344      * @s.tagattribute required="false"
345      */
346     public void setDoubleHeaderKey(String doubleHeaderKey) {
347     	this.doubleHeaderKey = doubleHeaderKey;
348     }
349     
350     public String getDoubleHeaderKey() {
351     	return doubleHeaderKey;
352     }
353     
354     /***
355      * The header value for the second list
356      * @s.tagattribute required="false"
357      */
358     public void setDoubleHeaderValue(String doubleHeaderValue) {
359     	this.doubleHeaderValue = doubleHeaderValue;
360     }
361     
362     public String getDoubleHeaderValue() {
363     	return doubleHeaderValue;
364     }
365 
366     /***
367      * Decides if the second list will add an empty option
368      * @s.tagattribute required="false"
369      */
370     public void setDoubleEmptyOption(String doubleEmptyOption) {
371     	this.doubleEmptyOption = doubleEmptyOption;
372     }
373     
374     public String getDoubleEmptyOption() {
375     	return this.doubleEmptyOption;
376     }
377 
378     
379 	public String getDoubleDisabled() {
380 		return doubleDisabled;
381 	}
382 
383 	/***
384      * Decides if a disable attribute should be added to the second list
385      * @s.tagattribute required="false"
386      */
387 	public void setDoubleDisabled(String doubleDisabled) {
388 		this.doubleDisabled = doubleDisabled;
389 	}
390 
391 	public String getDoubleId() {
392 		return doubleId;
393 	}
394 
395 	/***
396      * The id of the second list
397      * @s.tagattribute required="false"
398      */
399 	public void setDoubleId(String doubleId) {
400 		this.doubleId = doubleId;
401 	}
402 
403 	public String getDoubleMultiple() {
404 		return doubleMultiple;
405 	}
406 
407 	/***
408      * Decides if multiple attribute should be set on the second list
409      * @s.tagattribute required="false"
410      */
411 	public void setDoubleMultiple(String doubleMultiple) {
412 		this.doubleMultiple = doubleMultiple;
413 	}
414 
415 	public String getDoubleOnblur() {
416 		return doubleOnblur;
417 	}
418 
419 	/***
420      * Set the onblur attribute of the second list
421      * @s.tagattribute required="false"
422      */
423 	public void setDoubleOnblur(String doubleOnblur) {
424 		this.doubleOnblur = doubleOnblur;
425 	}
426 
427 	public String getDoubleOnchange() {
428 		return doubleOnchange;
429 	}
430 
431 	/***
432      * Set the onchange attribute of the second list
433      * @s.tagattribute required="false"
434      */
435 	public void setDoubleOnchange(String doubleOnchange) {
436 		this.doubleOnchange = doubleOnchange;
437 	}
438 
439 	public String getDoubleOnclick() {
440 		return doubleOnclick;
441 	}
442 
443 	/***
444      * Set the onclick attribute of the second list
445      * @s.tagattribute required="false"
446      */
447 	public void setDoubleOnclick(String doubleOnclick) {
448 		this.doubleOnclick = doubleOnclick;
449 	}
450 
451 	public String getDoubleOndblclick() {
452 		return doubleOndblclick;
453 	}
454 
455 	/***
456      * Set the ondbclick attribute of the second list
457      * @s.tagattribute required="false"
458      */
459 	public void setDoubleOndblclick(String doubleOndblclick) {
460 		this.doubleOndblclick = doubleOndblclick;
461 	}
462 
463 	public String getDoubleOnfocus() {
464 		return doubleOnfocus;
465 	}
466 
467 	/***
468      * Set the onfocus attribute of the second list
469      * @s.tagattribute required="false"
470      */
471 	public void setDoubleOnfocus(String doubleOnfocus) {
472 		this.doubleOnfocus = doubleOnfocus;
473 	}
474 
475 	public String getDoubleOnkeydown() {
476 		return doubleOnkeydown;
477 	}
478 
479 	/***
480      * Set the onkeydown attribute of the second list
481      * @s.tagattribute required="false"
482      */
483 	public void setDoubleOnkeydown(String doubleOnkeydown) {
484 		this.doubleOnkeydown = doubleOnkeydown;
485 	}
486 
487 	public String getDoubleOnkeypress() {
488 		return doubleOnkeypress;
489 	}
490 
491 	/***
492      * Set the onkeypress attribute of the second list
493      * @s.tagattribute required="false"
494      */
495 	public void setDoubleOnkeypress(String doubleOnkeypress) {
496 		this.doubleOnkeypress = doubleOnkeypress;
497 	}
498 
499 	public String getDoubleOnkeyup() {
500 		return doubleOnkeyup;
501 	}
502 
503 	/***
504      * Set the onkeyup attribute of the second list
505      * @s.tagattribute required="false"
506      */
507 	public void setDoubleOnkeyup(String doubleOnkeyup) {
508 		this.doubleOnkeyup = doubleOnkeyup;
509 	}
510 
511 	public String getDoubleOnmousedown() {
512 		return doubleOnmousedown;
513 	}
514 
515 	/***
516      * Set the onmousedown attribute of the second list
517      * @s.tagattribute required="false"
518      */
519 	public void setDoubleOnmousedown(String doubleOnmousedown) {
520 		this.doubleOnmousedown = doubleOnmousedown;
521 	}
522 
523 	public String getDoubleOnmousemove() {
524 		return doubleOnmousemove;
525 	}
526 
527 	/***
528      * Set the onmousemove attribute of the second list
529      * @s.tagattribute required="false"
530      */
531 	public void setDoubleOnmousemove(String doubleOnmousemove) {
532 		this.doubleOnmousemove = doubleOnmousemove;
533 	}
534 
535 	public String getDoubleOnmouseout() {
536 		return doubleOnmouseout;
537 	}
538 
539 	/***
540      * Set the onmouseout attribute of the second list
541      * @s.tagattribute required="false"
542      */
543 	public void setDoubleOnmouseout(String doubleOnmouseout) {
544 		this.doubleOnmouseout = doubleOnmouseout;
545 	}
546 
547 	public String getDoubleOnmouseover() {
548 		return doubleOnmouseover;
549 	}
550 
551 	/***
552      * Set the onmouseover attribute of the second list
553      * @s.tagattribute required="false"
554      */
555 	public void setDoubleOnmouseover(String doubleOnmouseover) {
556 		this.doubleOnmouseover = doubleOnmouseover;
557 	}
558 
559 	public String getDoubleOnmouseup() {
560 		return doubleOnmouseup;
561 	}
562 
563 	/***
564      * Set the onmouseup attribute of the second list
565      * @s.tagattribute required="false"
566      */
567 	public void setDoubleOnmouseup(String doubleOnmouseup) {
568 		this.doubleOnmouseup = doubleOnmouseup;
569 	}
570 
571 	public String getDoubleOnselect() {
572 		return doubleOnselect;
573 	}
574 
575 	/***
576      * Set the onselect attribute of the second list
577      * @s.tagattribute required="false"
578      */
579 	public void setDoubleOnselect(String doubleOnselect) {
580 		this.doubleOnselect = doubleOnselect;
581 	}
582 
583 	public String getDoubleSize() {
584 		return doubleSize;
585 	}
586 
587 	/***
588      * Set the size attribute of the second list
589      * @s.tagattribute required="false"
590      */
591 	public void setDoubleSize(String doubleSize) {
592 		this.doubleSize = doubleSize;
593 	}
594 
595 	public String getDoubleList() {
596 		return doubleList;
597 	}
598 
599 	/***
600      * Set the list key of the second attribute
601      * @s.tagattribute required="false"
602      */
603 	public String getDoubleListKey() {
604 		return doubleListKey;
605 	}
606 
607 	public String getDoubleListValue() {
608 		return doubleListValue;
609 	}
610 
611 	public String getDoubleName() {
612 		return doubleName;
613 	}
614 
615 	public String getDoubleValue() {
616 		return doubleValue;
617 	}
618 	
619 	/***
620      * Decides of an empty option is to be inserted in the second list
621      * @s.tagattribute required="false" default="false" type="Boolean"
622      */
623     public void setEmptyOption(String emptyOption) {
624         this.emptyOption = emptyOption;
625     }
626 
627     /***
628      * Set the header key of the second list. Must not be empty! "'-1'" and "''" is correct, "" is bad.
629      * @s.tagattribute required="false"
630      */
631     public void setHeaderKey(String headerKey) {
632         this.headerKey = headerKey;
633     }
634 
635     /***
636      * Set the header value of the second list
637      * @s.tagattribute required="false"
638      */
639     public void setHeaderValue(String headerValue) {
640         this.headerValue = headerValue;
641     }
642 
643     /***
644      * Creates a multiple select. The tag will pre-select multiple values if the values are passed as an Array (of appropriate types) via the value attribute.
645      * @s.tagattribute required="false"
646      */
647     public void setMultiple(String multiple) {
648         // TODO: Passing a Collection may work too?
649         this.multiple = multiple;
650     }
651 
652     /***
653      * Size of the element box (# of elements to show)
654      * @s.tagattribute required="false" type="Integer"
655      */
656     public void setSize(String size) {
657         this.size = size;
658     }
659     
660     /***
661      * Set the html accesskey attribute.
662      * @s.tagattribute required="false"
663      */
664     public void setDoubleAccesskey(String doubleAccesskey) {
665     	this.doubleAccesskey = doubleAccesskey;
666     }
667 }