View Javadoc

1   /*
2    * $Id: DoubleListUIBean.java 557345 2007-07-18 18:05:09Z jholmes $
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         } else {
196             addParameter("doubleId", escape(doubleName !=null ? findString(doubleName) : null));
197         }
198 
199         if (doubleOnclick != null) {
200             addParameter("doubleOnclick", findString(doubleOnclick));
201         }
202 
203         if (doubleOndblclick != null) {
204             addParameter("doubleOndblclick", findString(doubleOndblclick));
205         }
206 
207         if (doubleOnmousedown != null) {
208             addParameter("doubleOnmousedown", findString(doubleOnmousedown));
209         }
210 
211         if (doubleOnmouseup != null) {
212             addParameter("doubleOnmouseup", findString(doubleOnmouseup));
213         }
214 
215         if (doubleOnmouseover != null) {
216             addParameter("doubleOnmouseover", findString(doubleOnmouseover));
217         }
218 
219         if (doubleOnmousemove != null) {
220             addParameter("doubleOnmousemove", findString(doubleOnmousemove));
221         }
222 
223         if (doubleOnmouseout != null) {
224             addParameter("doubleOnmouseout", findString(doubleOnmouseout));
225         }
226 
227         if (doubleOnfocus != null) {
228             addParameter("doubleOnfocus", findString(doubleOnfocus));
229         }
230 
231         if (doubleOnblur != null) {
232             addParameter("doubleOnblur", findString(doubleOnblur));
233         }
234 
235         if (doubleOnkeypress != null) {
236             addParameter("doubleOnkeypress", findString(doubleOnkeypress));
237         }
238 
239         if (doubleOnkeydown != null) {
240             addParameter("doubleOnkeydown", findString(doubleOnkeydown));
241         }
242 
243         if (doubleOnselect != null) {
244             addParameter("doubleOnselect", findString(doubleOnselect));
245         }
246 
247         if (doubleOnchange != null) {
248             addParameter("doubleOnchange", findString(doubleOnchange));
249         }
250 
251         if (doubleCssClass != null) {
252             addParameter("doubleCss", findString(doubleCssClass));
253         }
254 
255         if (doubleCssStyle != null) {
256             addParameter("doubleStyle", findString(doubleCssStyle));
257         }
258 
259         if (doubleHeaderKey != null && doubleHeaderValue != null) {
260             addParameter("doubleHeaderKey", findString(doubleHeaderKey));
261             addParameter("doubleHeaderValue", findString(doubleHeaderValue));
262         }
263 
264         if (doubleEmptyOption != null) {
265             addParameter("doubleEmptyOption", findValue(doubleEmptyOption, Boolean.class));
266         }
267 
268         if (doubleAccesskey != null) {
269             addParameter("doubleAccesskey", findString(doubleAccesskey));
270         }
271     }
272 
273     @StrutsTagAttribute(description="The second iterable source to populate from.", required=true)
274     public void setDoubleList(String doubleList) {
275         this.doubleList = doubleList;
276     }
277 
278     @StrutsTagAttribute(description="The key expression to use for second list")
279     public void setDoubleListKey(String doubleListKey) {
280         this.doubleListKey = doubleListKey;
281     }
282 
283     @StrutsTagAttribute(description="The value expression to use for second list")
284     public void setDoubleListValue(String doubleListValue) {
285         this.doubleListValue = doubleListValue;
286     }
287 
288     @StrutsTagAttribute(description="The name for complete component", required=true)
289     public void setDoubleName(String doubleName) {
290         this.doubleName = doubleName;
291     }
292 
293     @StrutsTagAttribute(description="The value expression for complete component")
294     public void setDoubleValue(String doubleValue) {
295         this.doubleValue = doubleValue;
296     }
297 
298     @StrutsTagAttribute(description="The form name this component resides in and populates to")
299     public void setFormName(String formName) {
300         this.formName = formName;
301     }
302 
303     public String getFormName() {
304         return formName;
305     }
306 
307     @StrutsTagAttribute(description="The css class for the second list")
308     public void setDoubleCssClass(String doubleCssClass) {
309         this.doubleCssClass = doubleCssClass;
310     }
311 
312     public String getDoubleCssClass() {
313         return doubleCssClass;
314     }
315 
316     @StrutsTagAttribute(description="The css style for the second list")
317     public void setDoubleCssStyle(String doubleCssStyle) {
318         this.doubleCssStyle = doubleCssStyle;
319     }
320 
321     public String getDoubleCssStyle() {
322         return doubleCssStyle;
323     }
324 
325     @StrutsTagAttribute(description="The header key for the second list")
326     public void setDoubleHeaderKey(String doubleHeaderKey) {
327         this.doubleHeaderKey = doubleHeaderKey;
328     }
329 
330     public String getDoubleHeaderKey() {
331         return doubleHeaderKey;
332     }
333 
334     @StrutsTagAttribute(description="The header value for the second list")
335     public void setDoubleHeaderValue(String doubleHeaderValue) {
336         this.doubleHeaderValue = doubleHeaderValue;
337     }
338 
339     public String getDoubleHeaderValue() {
340         return doubleHeaderValue;
341     }
342 
343     @StrutsTagAttribute(description="Decides if the second list will add an empty option")
344     public void setDoubleEmptyOption(String doubleEmptyOption) {
345         this.doubleEmptyOption = doubleEmptyOption;
346     }
347 
348     public String getDoubleEmptyOption() {
349         return this.doubleEmptyOption;
350     }
351 
352 
353     public String getDoubleDisabled() {
354         return doubleDisabled;
355     }
356 
357     @StrutsTagAttribute(description="Decides if a disable attribute should be added to the second list")
358     public void setDoubleDisabled(String doubleDisabled) {
359         this.doubleDisabled = doubleDisabled;
360     }
361 
362     public String getDoubleId() {
363         return doubleId;
364     }
365 
366     @StrutsTagAttribute(description="The id of the second list")
367     public void setDoubleId(String doubleId) {
368         this.doubleId = doubleId;
369     }
370 
371     public String getDoubleMultiple() {
372         return doubleMultiple;
373     }
374 
375     @StrutsTagAttribute(description=" Decides if multiple attribute should be set on the second list")
376     public void setDoubleMultiple(String doubleMultiple) {
377         this.doubleMultiple = doubleMultiple;
378     }
379 
380     public String getDoubleOnblur() {
381         return doubleOnblur;
382     }
383 
384     @StrutsTagAttribute(description="Set the onblur attribute of the second list")
385     public void setDoubleOnblur(String doubleOnblur) {
386         this.doubleOnblur = doubleOnblur;
387     }
388 
389     public String getDoubleOnchange() {
390         return doubleOnchange;
391     }
392 
393     @StrutsTagAttribute(description="Set the onchange attribute of the second list")
394     public void setDoubleOnchange(String doubleOnchange) {
395         this.doubleOnchange = doubleOnchange;
396     }
397 
398     public String getDoubleOnclick() {
399         return doubleOnclick;
400     }
401 
402     @StrutsTagAttribute(description="Set the onclick attribute of the second list")
403     public void setDoubleOnclick(String doubleOnclick) {
404         this.doubleOnclick = doubleOnclick;
405     }
406 
407     public String getDoubleOndblclick() {
408         return doubleOndblclick;
409     }
410 
411     @StrutsTagAttribute(description="Set the ondbclick attribute of the second list")
412     public void setDoubleOndblclick(String doubleOndblclick) {
413         this.doubleOndblclick = doubleOndblclick;
414     }
415 
416     public String getDoubleOnfocus() {
417         return doubleOnfocus;
418     }
419 
420     @StrutsTagAttribute(description="Set the onfocus attribute of the second list")
421     public void setDoubleOnfocus(String doubleOnfocus) {
422         this.doubleOnfocus = doubleOnfocus;
423     }
424 
425     public String getDoubleOnkeydown() {
426         return doubleOnkeydown;
427     }
428 
429     @StrutsTagAttribute(description="Set the onkeydown attribute of the second list")
430     public void setDoubleOnkeydown(String doubleOnkeydown) {
431         this.doubleOnkeydown = doubleOnkeydown;
432     }
433 
434     public String getDoubleOnkeypress() {
435         return doubleOnkeypress;
436     }
437 
438     @StrutsTagAttribute(description="Set the onkeypress attribute of the second list")
439     public void setDoubleOnkeypress(String doubleOnkeypress) {
440         this.doubleOnkeypress = doubleOnkeypress;
441     }
442 
443     public String getDoubleOnkeyup() {
444         return doubleOnkeyup;
445     }
446 
447     @StrutsTagAttribute(description="Set the onkeyup attribute of the second list")
448     public void setDoubleOnkeyup(String doubleOnkeyup) {
449         this.doubleOnkeyup = doubleOnkeyup;
450     }
451 
452     public String getDoubleOnmousedown() {
453         return doubleOnmousedown;
454     }
455 
456     @StrutsTagAttribute(description="Set the onmousedown attribute of the second list")
457     public void setDoubleOnmousedown(String doubleOnmousedown) {
458         this.doubleOnmousedown = doubleOnmousedown;
459     }
460 
461     public String getDoubleOnmousemove() {
462         return doubleOnmousemove;
463     }
464 
465     @StrutsTagAttribute(description="Set the onmousemove attribute of the second list")
466     public void setDoubleOnmousemove(String doubleOnmousemove) {
467         this.doubleOnmousemove = doubleOnmousemove;
468     }
469 
470     public String getDoubleOnmouseout() {
471         return doubleOnmouseout;
472     }
473 
474     @StrutsTagAttribute(description="Set the onmouseout attribute of the second list")
475     public void setDoubleOnmouseout(String doubleOnmouseout) {
476         this.doubleOnmouseout = doubleOnmouseout;
477     }
478 
479     public String getDoubleOnmouseover() {
480         return doubleOnmouseover;
481     }
482 
483     @StrutsTagAttribute(description="Set the onmouseover attribute of the second list")
484     public void setDoubleOnmouseover(String doubleOnmouseover) {
485         this.doubleOnmouseover = doubleOnmouseover;
486     }
487 
488     public String getDoubleOnmouseup() {
489         return doubleOnmouseup;
490     }
491 
492     @StrutsTagAttribute(description="Set the onmouseup attribute of the second list")
493     public void setDoubleOnmouseup(String doubleOnmouseup) {
494         this.doubleOnmouseup = doubleOnmouseup;
495     }
496 
497     public String getDoubleOnselect() {
498         return doubleOnselect;
499     }
500 
501     @StrutsTagAttribute(description="Set the onselect attribute of the second list")
502     public void setDoubleOnselect(String doubleOnselect) {
503         this.doubleOnselect = doubleOnselect;
504     }
505 
506     public String getDoubleSize() {
507         return doubleSize;
508     }
509 
510     @StrutsTagAttribute(description="Set the size attribute of the second list")
511     public void setDoubleSize(String doubleSize) {
512         this.doubleSize = doubleSize;
513     }
514 
515     public String getDoubleList() {
516         return doubleList;
517     }
518 
519     public String getDoubleListKey() {
520         return doubleListKey;
521     }
522 
523     public String getDoubleListValue() {
524         return doubleListValue;
525     }
526 
527     public String getDoubleName() {
528         return doubleName;
529     }
530 
531     public String getDoubleValue() {
532         return doubleValue;
533     }
534 
535     @StrutsTagAttribute(description="Decides of an empty option is to be inserted in the second list", type="Boolean", defaultValue="false")
536     public void setEmptyOption(String emptyOption) {
537         this.emptyOption = emptyOption;
538     }
539 
540     @StrutsTagAttribute(description="Set the header key of the second list. Must not be empty! " +
541                 "'-1' and '' is correct, '' is bad.")
542     public void setHeaderKey(String headerKey) {
543         this.headerKey = headerKey;
544     }
545 
546     @StrutsTagAttribute(description=" Set the header value of the second list")
547     public void setHeaderValue(String headerValue) {
548         this.headerValue = headerValue;
549     }
550 
551     @StrutsTagAttribute(description="Creates a multiple select. " +
552                 "The tag will pre-select multiple values if the values are passed as an Array " +
553                 "(of appropriate types) via the value attribute.")
554     public void setMultiple(String multiple) {
555         // TODO: Passing a Collection may work too?
556         this.multiple = multiple;
557     }
558 
559     @StrutsTagAttribute(description="Size of the element box (# of elements to show)", type="Integer")
560     public void setSize(String size) {
561         this.size = size;
562     }
563 
564     @StrutsTagAttribute(description="Set the html accesskey attribute.")
565     public void setDoubleAccesskey(String doubleAccesskey) {
566         this.doubleAccesskey = doubleAccesskey;
567     }
568 }