1 | |
package org.seasar.cubby.tags; |
2 | |
|
3 | |
import java.io.IOException; |
4 | |
import java.util.Map; |
5 | |
|
6 | |
import javax.servlet.jsp.JspException; |
7 | |
import javax.servlet.jsp.JspWriter; |
8 | |
import javax.servlet.jsp.PageContext; |
9 | |
|
10 | |
import org.seasar.cubby.util.CubbyFunctions; |
11 | |
import org.seasar.cubby.util.CubbyHelperFunctions; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 13 | public class InputTag extends DynamicAttributesTagSupport { |
27 | |
|
28 | |
private String type; |
29 | |
|
30 | |
public String getType() { |
31 | |
return type; |
32 | |
} |
33 | |
|
34 | |
public void setType(final String type) { |
35 | 13 | this.type = type; |
36 | 13 | } |
37 | |
|
38 | |
@SuppressWarnings("unchecked") |
39 | |
@Override |
40 | |
public void doTag() throws JspException, IOException { |
41 | 13 | final Map fieldErros = (Map) getJspContext().getAttribute("fieldErrors", PageContext.REQUEST_SCOPE); |
42 | 13 | if (fieldErros.get(getDynamicAttribute().get("name")) != null) { |
43 | |
CubbyHelperFunctions.addClassName(getDynamicAttribute(), "fieldError"); |
44 | |
} |
45 | |
|
46 | 13 | final JspWriter out = getJspContext().getOut(); |
47 | 13 | final Object form = getJspContext().getAttribute("__form", PageContext.REQUEST_SCOPE); |
48 | 13 | if ("checkbox".equals(type) || "radio".equals(type)) { |
49 | 10 | if (!getDynamicAttribute().containsKey("value")) { |
50 | 2 | throw new JspException("'value' attribute required."); |
51 | |
} |
52 | 8 | final String value = toString(getDynamicAttribute().get("value")); |
53 | 8 | final Object checkedValue = CubbyHelperFunctions.formMultiValue(getDynamicAttribute(), form, getJspContext(), "checkedValue"); |
54 | 8 | getJspContext().setAttribute("value", value, PageContext.PAGE_SCOPE); |
55 | 8 | getJspContext().setAttribute("checkedValue", checkedValue, PageContext.PAGE_SCOPE); |
56 | 8 | out.write("<input type=\""); |
57 | 8 | out.write(type); |
58 | 8 | out.write("\" value=\""); |
59 | 8 | out.write(CubbyFunctions.out(value)); |
60 | 8 | out.write("\" "); |
61 | 8 | out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute())); |
62 | 8 | out.write(" "); |
63 | 8 | out.write(CubbyHelperFunctions.checked(value, checkedValue)); |
64 | 8 | out.write("/>\n"); |
65 | 8 | } else { |
66 | 3 | final Object value = CubbyHelperFunctions.formValue(getDynamicAttribute(), form, getJspContext(), "value"); |
67 | |
|
68 | 3 | getJspContext().setAttribute("value", value, PageContext.PAGE_SCOPE); |
69 | |
|
70 | 3 | out.write("<input type=\""); |
71 | 3 | out.write(type); |
72 | 3 | out.write("\" value=\""); |
73 | 3 | if (getDynamicAttribute().containsKey("value")) { |
74 | 3 | out.write(CubbyFunctions.out(value)); |
75 | 3 | } else { |
76 | |
out.write(CubbyHelperFunctions.convertFieldValue(value, form, getRequest(), toString(getDynamicAttribute().get("name")))); |
77 | |
} |
78 | 3 | out.write("\" "); |
79 | 3 | out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute())); |
80 | 3 | out.write("/>\n"); |
81 | |
} |
82 | 11 | } |
83 | |
} |