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 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 this.type = type;
36 }
37
38 @SuppressWarnings("unchecked")
39 @Override
40 public void doTag() throws JspException, IOException {
41 final Map fieldErros = (Map) getJspContext().getAttribute("fieldErrors", PageContext.REQUEST_SCOPE);
42 if (fieldErros.get(getDynamicAttribute().get("name")) != null) {
43 CubbyHelperFunctions.addClassName(getDynamicAttribute(), "fieldError");
44 }
45
46 final JspWriter out = getJspContext().getOut();
47 final Object form = getJspContext().getAttribute("__form", PageContext.REQUEST_SCOPE);
48 if ("checkbox".equals(type) || "radio".equals(type)) {
49 if (!getDynamicAttribute().containsKey("value")) {
50 throw new JspException("'value' attribute required.");
51 }
52 final String value = toString(getDynamicAttribute().get("value"));
53 final Object checkedValue = CubbyHelperFunctions.formMultiValue(getDynamicAttribute(), form, getJspContext(), "checkedValue");
54 getJspContext().setAttribute("value", value, PageContext.PAGE_SCOPE);
55 getJspContext().setAttribute("checkedValue", checkedValue, PageContext.PAGE_SCOPE);
56 out.write("<input type=\"");
57 out.write(type);
58 out.write("\" value=\"");
59 out.write(CubbyFunctions.out(value));
60 out.write("\" ");
61 out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute()));
62 out.write(" ");
63 out.write(CubbyHelperFunctions.checked(value, checkedValue));
64 out.write("/>\n");
65 } else {
66 final Object value = CubbyHelperFunctions.formValue(getDynamicAttribute(), form, getJspContext(), "value");
67
68 getJspContext().setAttribute("value", value, PageContext.PAGE_SCOPE);
69
70 out.write("<input type=\"");
71 out.write(type);
72 out.write("\" value=\"");
73 if (getDynamicAttribute().containsKey("value")) {
74 out.write(CubbyFunctions.out(value));
75 } else {
76 out.write(CubbyHelperFunctions.convertFieldValue(value, form, getRequest(), toString(getDynamicAttribute().get("name"))));
77 }
78 out.write("\" ");
79 out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute()));
80 out.write("/>\n");
81 }
82 }
83 }