View Javadoc

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