001: /*
002: * $Id: DoubleListUIBean.java 557345 2007-07-18 18:05:09Z jholmes $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import java.util.Map;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.struts2.views.annotations.StrutsTagAttribute;
029:
030: import com.opensymphony.xwork2.util.ValueStack;
031:
032: /**
033: * DoubleListUIBean is the standard superclass of all Struts double list handling components.
034: *
035: * <p/>
036: *
037: * <!-- START SNIPPET: javadoc -->
038: *
039: * Note that the doublelistkey and doublelistvalue attribute will default to "key" and "value"
040: * respectively only when the doublelist attribute is evaluated to a Map or its decendant.
041: * Other thing else, will result in doublelistkey and doublelistvalue to be null and not used.
042: *
043: * <!-- END SNIPPET: javadoc -->
044: *
045: */
046: public abstract class DoubleListUIBean extends ListUIBean {
047:
048: protected String emptyOption;
049: protected String headerKey;
050: protected String headerValue;
051: protected String multiple;
052: protected String size;
053:
054: protected String doubleList;
055: protected String doubleListKey;
056: protected String doubleListValue;
057: protected String doubleName;
058: protected String doubleValue;
059: protected String formName;
060:
061: protected String doubleId;
062: protected String doubleDisabled;
063: protected String doubleMultiple;
064: protected String doubleSize;
065: protected String doubleHeaderKey;
066: protected String doubleHeaderValue;
067: protected String doubleEmptyOption;
068:
069: protected String doubleCssClass;
070: protected String doubleCssStyle;
071:
072: protected String doubleOnclick;
073: protected String doubleOndblclick;
074: protected String doubleOnmousedown;
075: protected String doubleOnmouseup;
076: protected String doubleOnmouseover;
077: protected String doubleOnmousemove;
078: protected String doubleOnmouseout;
079: protected String doubleOnfocus;
080: protected String doubleOnblur;
081: protected String doubleOnkeypress;
082: protected String doubleOnkeydown;
083: protected String doubleOnkeyup;
084: protected String doubleOnselect;
085: protected String doubleOnchange;
086:
087: protected String doubleAccesskey;
088:
089: public DoubleListUIBean(ValueStack stack,
090: HttpServletRequest request, HttpServletResponse response) {
091: super (stack, request, response);
092: }
093:
094: public void evaluateExtraParams() {
095: super .evaluateExtraParams();
096:
097: //Object doubleName = null;
098:
099: if (emptyOption != null) {
100: addParameter("emptyOption", findValue(emptyOption,
101: 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: if (doubleMultiple != null) {
118: addParameter("doubleMultiple", findValue(doubleMultiple,
119: Boolean.class));
120: }
121:
122: if (doubleSize != null) {
123: addParameter("doubleSize", findString(doubleSize));
124: }
125:
126: if (doubleDisabled != null) {
127: addParameter("doubleDisabled", findValue(doubleDisabled,
128: Boolean.class));
129: }
130:
131: if (doubleName != null) {
132: addParameter("doubleName", findString(this .doubleName));
133: }
134:
135: if (doubleList != null) {
136: addParameter("doubleList", doubleList);
137: }
138:
139: Object tmpDoubleList = findValue(doubleList);
140: if (doubleListKey != null) {
141: addParameter("doubleListKey", doubleListKey);
142: } else if (tmpDoubleList instanceof Map) {
143: addParameter("doubleListKey", "key");
144: }
145:
146: if (doubleListValue != null) {
147: if (altSyntax()) {
148: // the same logic as with findValue(String)
149: // if value start with %{ and end with }, just cut it off!
150: if (doubleListValue.startsWith("%{")
151: && doubleListValue.endsWith("}")) {
152: doubleListValue = doubleListValue.substring(2,
153: doubleListValue.length() - 1);
154: }
155: }
156:
157: addParameter("doubleListValue", doubleListValue);
158: } else if (tmpDoubleList instanceof Map) {
159: addParameter("doubleListValue", "value");
160: }
161:
162: if (formName != null) {
163: addParameter("formName", findString(formName));
164: } else {
165: // ok, let's look it up
166: Component form = findAncestor(Form.class);
167: if (form != null) {
168: addParameter("formName", form.getParameters().get(
169: "name"));
170: }
171: }
172:
173: Class valueClazz = getValueClassType();
174:
175: if (valueClazz != null) {
176: if (doubleValue != null) {
177: addParameter("doubleNameValue", findValue(doubleValue,
178: valueClazz));
179: } else if (doubleName != null) {
180: addParameter("doubleNameValue", findValue(doubleName
181: .toString(), valueClazz));
182: }
183: } else {
184: if (doubleValue != null) {
185: addParameter("doubleNameValue", findValue(doubleValue));
186: } else if (doubleName != null) {
187: addParameter("doubleNameValue", findValue(doubleName
188: .toString()));
189: }
190: }
191:
192: Form form = (Form) findAncestor(Form.class);
193: if (doubleId != null) {
194: // this check is needed for backwards compatibility with 2.1.x
195: if (altSyntax()) {
196: addParameter("doubleId", findString(doubleId));
197: } else {
198: addParameter("doubleId", doubleId);
199: }
200: } else if (form != null) {
201: addParameter("doubleId", form.getParameters().get("id")
202: + "_" + escape(this .doubleName));
203: } else {
204: addParameter("doubleId",
205: escape(doubleName != null ? findString(doubleName)
206: : null));
207: }
208:
209: if (doubleOnclick != null) {
210: addParameter("doubleOnclick", findString(doubleOnclick));
211: }
212:
213: if (doubleOndblclick != null) {
214: addParameter("doubleOndblclick",
215: findString(doubleOndblclick));
216: }
217:
218: if (doubleOnmousedown != null) {
219: addParameter("doubleOnmousedown",
220: findString(doubleOnmousedown));
221: }
222:
223: if (doubleOnmouseup != null) {
224: addParameter("doubleOnmouseup", findString(doubleOnmouseup));
225: }
226:
227: if (doubleOnmouseover != null) {
228: addParameter("doubleOnmouseover",
229: findString(doubleOnmouseover));
230: }
231:
232: if (doubleOnmousemove != null) {
233: addParameter("doubleOnmousemove",
234: findString(doubleOnmousemove));
235: }
236:
237: if (doubleOnmouseout != null) {
238: addParameter("doubleOnmouseout",
239: findString(doubleOnmouseout));
240: }
241:
242: if (doubleOnfocus != null) {
243: addParameter("doubleOnfocus", findString(doubleOnfocus));
244: }
245:
246: if (doubleOnblur != null) {
247: addParameter("doubleOnblur", findString(doubleOnblur));
248: }
249:
250: if (doubleOnkeypress != null) {
251: addParameter("doubleOnkeypress",
252: findString(doubleOnkeypress));
253: }
254:
255: if (doubleOnkeydown != null) {
256: addParameter("doubleOnkeydown", findString(doubleOnkeydown));
257: }
258:
259: if (doubleOnselect != null) {
260: addParameter("doubleOnselect", findString(doubleOnselect));
261: }
262:
263: if (doubleOnchange != null) {
264: addParameter("doubleOnchange", findString(doubleOnchange));
265: }
266:
267: if (doubleCssClass != null) {
268: addParameter("doubleCss", findString(doubleCssClass));
269: }
270:
271: if (doubleCssStyle != null) {
272: addParameter("doubleStyle", findString(doubleCssStyle));
273: }
274:
275: if (doubleHeaderKey != null && doubleHeaderValue != null) {
276: addParameter("doubleHeaderKey", findString(doubleHeaderKey));
277: addParameter("doubleHeaderValue",
278: findString(doubleHeaderValue));
279: }
280:
281: if (doubleEmptyOption != null) {
282: addParameter("doubleEmptyOption", findValue(
283: doubleEmptyOption, Boolean.class));
284: }
285:
286: if (doubleAccesskey != null) {
287: addParameter("doubleAccesskey", findString(doubleAccesskey));
288: }
289: }
290:
291: @StrutsTagAttribute(description="The second iterable source to populate from.",required=true)
292: public void setDoubleList(String doubleList) {
293: this .doubleList = doubleList;
294: }
295:
296: @StrutsTagAttribute(description="The key expression to use for second list")
297: public void setDoubleListKey(String doubleListKey) {
298: this .doubleListKey = doubleListKey;
299: }
300:
301: @StrutsTagAttribute(description="The value expression to use for second list")
302: public void setDoubleListValue(String doubleListValue) {
303: this .doubleListValue = doubleListValue;
304: }
305:
306: @StrutsTagAttribute(description="The name for complete component",required=true)
307: public void setDoubleName(String doubleName) {
308: this .doubleName = doubleName;
309: }
310:
311: @StrutsTagAttribute(description="The value expression for complete component")
312: public void setDoubleValue(String doubleValue) {
313: this .doubleValue = doubleValue;
314: }
315:
316: @StrutsTagAttribute(description="The form name this component resides in and populates to")
317: public void setFormName(String formName) {
318: this .formName = formName;
319: }
320:
321: public String getFormName() {
322: return formName;
323: }
324:
325: @StrutsTagAttribute(description="The css class for the second list")
326: public void setDoubleCssClass(String doubleCssClass) {
327: this .doubleCssClass = doubleCssClass;
328: }
329:
330: public String getDoubleCssClass() {
331: return doubleCssClass;
332: }
333:
334: @StrutsTagAttribute(description="The css style for the second list")
335: public void setDoubleCssStyle(String doubleCssStyle) {
336: this .doubleCssStyle = doubleCssStyle;
337: }
338:
339: public String getDoubleCssStyle() {
340: return doubleCssStyle;
341: }
342:
343: @StrutsTagAttribute(description="The header key for the second list")
344: public void setDoubleHeaderKey(String doubleHeaderKey) {
345: this .doubleHeaderKey = doubleHeaderKey;
346: }
347:
348: public String getDoubleHeaderKey() {
349: return doubleHeaderKey;
350: }
351:
352: @StrutsTagAttribute(description="The header value for the second list")
353: public void setDoubleHeaderValue(String doubleHeaderValue) {
354: this .doubleHeaderValue = doubleHeaderValue;
355: }
356:
357: public String getDoubleHeaderValue() {
358: return doubleHeaderValue;
359: }
360:
361: @StrutsTagAttribute(description="Decides if the second list will add an empty option")
362: public void setDoubleEmptyOption(String doubleEmptyOption) {
363: this .doubleEmptyOption = doubleEmptyOption;
364: }
365:
366: public String getDoubleEmptyOption() {
367: return this .doubleEmptyOption;
368: }
369:
370: public String getDoubleDisabled() {
371: return doubleDisabled;
372: }
373:
374: @StrutsTagAttribute(description="Decides if a disable attribute should be added to the second list")
375: public void setDoubleDisabled(String doubleDisabled) {
376: this .doubleDisabled = doubleDisabled;
377: }
378:
379: public String getDoubleId() {
380: return doubleId;
381: }
382:
383: @StrutsTagAttribute(description="The id of the second list")
384: public void setDoubleId(String doubleId) {
385: this .doubleId = doubleId;
386: }
387:
388: public String getDoubleMultiple() {
389: return doubleMultiple;
390: }
391:
392: @StrutsTagAttribute(description=" Decides if multiple attribute should be set on the second list")
393: public void setDoubleMultiple(String doubleMultiple) {
394: this .doubleMultiple = doubleMultiple;
395: }
396:
397: public String getDoubleOnblur() {
398: return doubleOnblur;
399: }
400:
401: @StrutsTagAttribute(description="Set the onblur attribute of the second list")
402: public void setDoubleOnblur(String doubleOnblur) {
403: this .doubleOnblur = doubleOnblur;
404: }
405:
406: public String getDoubleOnchange() {
407: return doubleOnchange;
408: }
409:
410: @StrutsTagAttribute(description="Set the onchange attribute of the second list")
411: public void setDoubleOnchange(String doubleOnchange) {
412: this .doubleOnchange = doubleOnchange;
413: }
414:
415: public String getDoubleOnclick() {
416: return doubleOnclick;
417: }
418:
419: @StrutsTagAttribute(description="Set the onclick attribute of the second list")
420: public void setDoubleOnclick(String doubleOnclick) {
421: this .doubleOnclick = doubleOnclick;
422: }
423:
424: public String getDoubleOndblclick() {
425: return doubleOndblclick;
426: }
427:
428: @StrutsTagAttribute(description="Set the ondbclick attribute of the second list")
429: public void setDoubleOndblclick(String doubleOndblclick) {
430: this .doubleOndblclick = doubleOndblclick;
431: }
432:
433: public String getDoubleOnfocus() {
434: return doubleOnfocus;
435: }
436:
437: @StrutsTagAttribute(description="Set the onfocus attribute of the second list")
438: public void setDoubleOnfocus(String doubleOnfocus) {
439: this .doubleOnfocus = doubleOnfocus;
440: }
441:
442: public String getDoubleOnkeydown() {
443: return doubleOnkeydown;
444: }
445:
446: @StrutsTagAttribute(description="Set the onkeydown attribute of the second list")
447: public void setDoubleOnkeydown(String doubleOnkeydown) {
448: this .doubleOnkeydown = doubleOnkeydown;
449: }
450:
451: public String getDoubleOnkeypress() {
452: return doubleOnkeypress;
453: }
454:
455: @StrutsTagAttribute(description="Set the onkeypress attribute of the second list")
456: public void setDoubleOnkeypress(String doubleOnkeypress) {
457: this .doubleOnkeypress = doubleOnkeypress;
458: }
459:
460: public String getDoubleOnkeyup() {
461: return doubleOnkeyup;
462: }
463:
464: @StrutsTagAttribute(description="Set the onkeyup attribute of the second list")
465: public void setDoubleOnkeyup(String doubleOnkeyup) {
466: this .doubleOnkeyup = doubleOnkeyup;
467: }
468:
469: public String getDoubleOnmousedown() {
470: return doubleOnmousedown;
471: }
472:
473: @StrutsTagAttribute(description="Set the onmousedown attribute of the second list")
474: public void setDoubleOnmousedown(String doubleOnmousedown) {
475: this .doubleOnmousedown = doubleOnmousedown;
476: }
477:
478: public String getDoubleOnmousemove() {
479: return doubleOnmousemove;
480: }
481:
482: @StrutsTagAttribute(description="Set the onmousemove attribute of the second list")
483: public void setDoubleOnmousemove(String doubleOnmousemove) {
484: this .doubleOnmousemove = doubleOnmousemove;
485: }
486:
487: public String getDoubleOnmouseout() {
488: return doubleOnmouseout;
489: }
490:
491: @StrutsTagAttribute(description="Set the onmouseout attribute of the second list")
492: public void setDoubleOnmouseout(String doubleOnmouseout) {
493: this .doubleOnmouseout = doubleOnmouseout;
494: }
495:
496: public String getDoubleOnmouseover() {
497: return doubleOnmouseover;
498: }
499:
500: @StrutsTagAttribute(description="Set the onmouseover attribute of the second list")
501: public void setDoubleOnmouseover(String doubleOnmouseover) {
502: this .doubleOnmouseover = doubleOnmouseover;
503: }
504:
505: public String getDoubleOnmouseup() {
506: return doubleOnmouseup;
507: }
508:
509: @StrutsTagAttribute(description="Set the onmouseup attribute of the second list")
510: public void setDoubleOnmouseup(String doubleOnmouseup) {
511: this .doubleOnmouseup = doubleOnmouseup;
512: }
513:
514: public String getDoubleOnselect() {
515: return doubleOnselect;
516: }
517:
518: @StrutsTagAttribute(description="Set the onselect attribute of the second list")
519: public void setDoubleOnselect(String doubleOnselect) {
520: this .doubleOnselect = doubleOnselect;
521: }
522:
523: public String getDoubleSize() {
524: return doubleSize;
525: }
526:
527: @StrutsTagAttribute(description="Set the size attribute of the second list")
528: public void setDoubleSize(String doubleSize) {
529: this .doubleSize = doubleSize;
530: }
531:
532: public String getDoubleList() {
533: return doubleList;
534: }
535:
536: public String getDoubleListKey() {
537: return doubleListKey;
538: }
539:
540: public String getDoubleListValue() {
541: return doubleListValue;
542: }
543:
544: public String getDoubleName() {
545: return doubleName;
546: }
547:
548: public String getDoubleValue() {
549: return doubleValue;
550: }
551:
552: @StrutsTagAttribute(description="Decides of an empty option is to be inserted in the second list",type="Boolean",defaultValue="false")
553: public void setEmptyOption(String emptyOption) {
554: this .emptyOption = emptyOption;
555: }
556:
557: @StrutsTagAttribute(description="Set the header key of the second list. Must not be empty! " + "'-1' and '' is correct, '' is bad.")
558: public void setHeaderKey(String headerKey) {
559: this .headerKey = headerKey;
560: }
561:
562: @StrutsTagAttribute(description=" Set the header value of the second list")
563: public void setHeaderValue(String headerValue) {
564: this .headerValue = headerValue;
565: }
566:
567: @StrutsTagAttribute(description="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.")
568: public void setMultiple(String multiple) {
569: // TODO: Passing a Collection may work too?
570: this .multiple = multiple;
571: }
572:
573: @StrutsTagAttribute(description="Size of the element box (# of elements to show)",type="Integer")
574: public void setSize(String size) {
575: this .size = size;
576: }
577:
578: @StrutsTagAttribute(description="Set the html accesskey attribute.")
579: public void setDoubleAccesskey(String doubleAccesskey) {
580: this.doubleAccesskey = doubleAccesskey;
581: }
582: }
|