| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.web.tagext; |
| 33 |
|
|
| 34 |
|
import javax.servlet.jsp.JspException; |
| 35 |
|
import javax.servlet.jsp.JspTagException; |
| 36 |
|
import javax.servlet.jsp.JspWriter; |
| 37 |
|
import javax.servlet.jsp.tagext.TagSupport; |
| 38 |
|
import java.lang.reflect.Method; |
| 39 |
|
import java.util.Arrays; |
| 40 |
|
import java.util.Collection; |
| 41 |
|
import java.util.Iterator; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@author |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 80 (80) |
Complexity: 20 |
Complexity Density: 0,4 |
|
| 49 |
|
public class SelectTag extends TagSupport { |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
private Collection items; |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
private String name; |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
private int size = -1; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
private boolean multiple = false; |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
private String label; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
private String value; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
private Object selected; |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
|
|
|
| 0% |
Uncovered Elements: 58 (58) |
Complexity: 11 |
Complexity Density: 0,28 |
|
| 75 |
0
|
public int doStartTag() throws JspException {... |
| 76 |
|
|
| 77 |
0
|
Iterator iterator = items.iterator(); |
| 78 |
|
|
| 79 |
0
|
try { |
| 80 |
0
|
JspWriter out = pageContext.getOut(); |
| 81 |
|
|
| 82 |
|
|
| 83 |
0
|
out.print("<select name=\""); |
| 84 |
0
|
out.print(name); |
| 85 |
0
|
out.print("\""); |
| 86 |
|
|
| 87 |
0
|
if (size > 0) { |
| 88 |
0
|
out.print(" size=\""); |
| 89 |
0
|
out.print(size); |
| 90 |
0
|
out.print("\""); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
0
|
if (multiple) { |
| 94 |
0
|
out.print(" multiple=\"true\""); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
0
|
out.print(">"); |
| 98 |
|
|
| 99 |
0
|
while (iterator.hasNext()) { |
| 100 |
|
|
| 101 |
0
|
Object o = iterator.next(); |
| 102 |
|
|
| 103 |
|
|
| 104 |
0
|
String hiddenValue; |
| 105 |
0
|
if (value != null) { |
| 106 |
0
|
Method m = o.getClass().getMethod("get" + value.substring(0, 1).toUpperCase() + value.substring(1), new Class[] {}); |
| 107 |
0
|
hiddenValue = m.invoke(o, new Object[]{}).toString(); |
| 108 |
|
} else { |
| 109 |
0
|
hiddenValue = o.toString(); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
0
|
out.print("<option value=\""); |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
0
|
out.print(hiddenValue); |
| 119 |
0
|
out.print("\""); |
| 120 |
|
|
| 121 |
0
|
if (selected != null) { |
| 122 |
0
|
if (selected instanceof Collection) { |
| 123 |
0
|
Collection coll = (Collection)selected; |
| 124 |
0
|
if (coll.contains(hiddenValue)) { |
| 125 |
0
|
out.print(" selected=\"true\""); |
| 126 |
|
} |
| 127 |
0
|
} else if (selected.toString().equals(hiddenValue)) { |
| 128 |
0
|
out.print(" selected=\"true\""); |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
0
|
out.print(">"); |
| 132 |
|
|
| 133 |
0
|
if (label != null) { |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
0
|
Method m = o.getClass().getMethod("get" + label.substring(0, 1).toUpperCase() + label.substring(1), new Class[] {}); |
| 138 |
0
|
out.print( |
| 139 |
|
m.invoke(o, new Object[]{})); |
| 140 |
|
} else { |
| 141 |
0
|
out.print(o.toString()); |
| 142 |
|
} |
| 143 |
0
|
out.print("</option>"); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
0
|
out.print("</select>"); |
| 148 |
|
} catch (Exception e) { |
| 149 |
0
|
e.printStackTrace(); |
| 150 |
0
|
throw new JspTagException(e.getMessage()); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
0
|
return SKIP_BODY; |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
@param |
| 161 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0,75 |
|
| 162 |
0
|
public void setItems(Object items) {... |
| 163 |
0
|
if (items instanceof Collection) { |
| 164 |
0
|
this.items = (Collection)items; |
| 165 |
0
|
} else if (items instanceof Object[]) { |
| 166 |
0
|
this.items = Arrays.asList((Object[])items); |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
@param |
| 174 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 175 |
0
|
public void setName(String name) {... |
| 176 |
0
|
this.name = name; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
@param |
| 183 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 184 |
0
|
public void setSize(int size) {... |
| 185 |
0
|
this.size = size; |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
@param |
| 192 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 193 |
0
|
public void setMultiple(boolean multiple) {... |
| 194 |
0
|
this.multiple = multiple; |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
@param |
| 201 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 202 |
0
|
public void setLabel(String label) {... |
| 203 |
0
|
this.label = label; |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
@param |
| 210 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 211 |
0
|
public void setValue(String value) {... |
| 212 |
0
|
this.value = value; |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
@param |
| 219 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 220 |
0
|
public void setSelected(Object selected) {... |
| 221 |
0
|
this.selected = selected; |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
} |