View Javadoc

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