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 ; 8 import javax.servlet.http.HttpServletResponse ; 9 import java.lang.reflect.Array ; 10 import java.util.Collection ; 11 import java.util.Map ; 12 13 18 public abstract class ListUIBean extends UIBean { 19 protected String list; 20 protected String listKey; 21 protected String listValue; 22 23 protected ListUIBean(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { 24 super(stack, request, response); 25 } 26 27 public void evaluateExtraParams() { 28 Object value = findValue(list); 29 30 if (list != null) { 31 if (value instanceof Collection ) { 32 addParameter("list", value); 33 } else { 34 addParameter("list", MakeIterator.convert(value)); 35 } 36 37 if (value instanceof Collection ) { 38 addParameter("listSize", new Integer (((Collection ) value).size())); 39 } else if (value instanceof Map ) { 40 addParameter("listSize", new Integer (((Map ) value).size())); 41 } else if (value != null && value.getClass().isArray()) { 42 addParameter("listSize", new Integer (Array.getLength(value))); 43 } 44 } 45 46 if (listKey != null) { 47 addParameter("listKey", listKey); 48 } else if (value instanceof Map ) { 49 addParameter("listKey", "key"); 50 } 51 52 if (listValue != null) { 53 addParameter("listValue", listValue); 54 } else if (value instanceof Map ) { 55 addParameter("listValue", "value"); 56 } 57 } 58 59 public boolean contains(Object obj1, Object obj2) { 60 return ContainUtil.contains(obj1, obj2); 61 } 62 63 protected Class getValueClassType() { 64 return null; } 66 67 public void setList(String list) { 68 this.list = list; 69 } 70 71 public void setListKey(String listKey) { 72 this.listKey = listKey; 73 } 74 75 public void setListValue(String listValue) { 76 this.listValue = listValue; 77 } 78 } 79 | Popular Tags |