KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > components > ListUIBean


1 package com.opensymphony.webwork.components;
2
3 import com.opensymphony.webwork.util.MakeIterator;
4 import com.opensymphony.webwork.util.ContainUtil;
5 import com.opensymphony.xwork.util.OgnlValueStack;
6
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9 import java.lang.reflect.Array JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Map JavaDoc;
12
13 /**
14  * User: plightbo
15  * Date: Jul 20, 2005
16  * Time: 7:58:43 AM
17  */

18 public abstract class ListUIBean extends UIBean {
19     protected String JavaDoc list;
20     protected String JavaDoc listKey;
21     protected String JavaDoc listValue;
22
23     protected ListUIBean(OgnlValueStack stack, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
24         super(stack, request, response);
25     }
26
27     public void evaluateExtraParams() {
28         Object JavaDoc value = findValue(list);
29
30         if (list != null) {
31             if (value instanceof Collection JavaDoc) {
32                 addParameter("list", value);
33             } else {
34                 addParameter("list", MakeIterator.convert(value));
35             }
36
37             if (value instanceof Collection JavaDoc) {
38                 addParameter("listSize", new Integer JavaDoc(((Collection JavaDoc) value).size()));
39             } else if (value instanceof Map JavaDoc) {
40                 addParameter("listSize", new Integer JavaDoc(((Map JavaDoc) value).size()));
41             } else if (value != null && value.getClass().isArray()) {
42                 addParameter("listSize", new Integer JavaDoc(Array.getLength(value)));
43             }
44         }
45
46         if (listKey != null) {
47             addParameter("listKey", listKey);
48         } else if (value instanceof Map JavaDoc) {
49             addParameter("listKey", "key");
50         }
51
52         if (listValue != null) {
53             addParameter("listValue", listValue);
54         } else if (value instanceof Map JavaDoc) {
55             addParameter("listValue", "value");
56         }
57     }
58
59     public boolean contains(Object JavaDoc obj1, Object JavaDoc obj2) {
60         return ContainUtil.contains(obj1, obj2);
61     }
62
63     protected Class JavaDoc getValueClassType() {
64         return null; // don't convert nameValue to anything, we need the raw value
65
}
66
67     public void setList(String JavaDoc list) {
68         this.list = list;
69     }
70
71     public void setListKey(String JavaDoc listKey) {
72         this.listKey = listKey;
73     }
74
75     public void setListValue(String JavaDoc listValue) {
76         this.listValue = listValue;
77     }
78 }
79
Popular Tags