1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.tags;
17
18 import static org.seasar.cubby.tags.TagUtils.addClassName;
19 import static org.seasar.cubby.tags.TagUtils.errors;
20 import static org.seasar.cubby.tags.TagUtils.formValue;
21 import static org.seasar.cubby.tags.TagUtils.outputValues;
22 import static org.seasar.cubby.tags.TagUtils.toAttr;
23
24 import java.io.IOException;
25 import java.util.Map;
26
27 import javax.servlet.jsp.JspContext;
28 import javax.servlet.jsp.JspException;
29 import javax.servlet.jsp.JspWriter;
30
31 import org.seasar.cubby.action.ActionErrors;
32 import org.seasar.cubby.util.CubbyFunctions;
33
34
35
36
37
38
39
40
41 public class TextareaTag extends DynamicAttributesTagSupport {
42
43 private String name;
44
45 private Object value;
46
47 private Integer index;
48
49
50
51
52
53
54
55 public void setName(final String name) {
56 this.name = name;
57 }
58
59
60
61
62
63
64
65 public void setValue(final Object value) {
66 this.value = value;
67 }
68
69
70
71
72
73
74
75 public void setIndex(final Integer index) {
76 this.index = index;
77 }
78
79
80
81
82 @Override
83 public void doTag() throws JspException, IOException {
84 final JspContext context = this.getJspContext();
85 final JspWriter out = context.getOut();
86 final ActionErrors errors = errors(context);
87 final Map<String, Object> dyn = this.getDynamicAttribute();
88 final Map<String, String[]> outputValues = outputValues(context);
89
90 if (this.index == null) {
91 if (!errors.getFields().get(this.name).isEmpty()) {
92 addClassName(dyn, "fieldError");
93 }
94 } else {
95 if (!errors.getIndexedFields().get(this.name).get(this.index)
96 .isEmpty()) {
97 addClassName(dyn, "fieldError");
98 }
99 }
100 final Object value = formValue(context, outputValues, this.name,
101 this.index, this.value);
102
103 out.write("<textarea name=\"");
104 out.write(this.name);
105 out.write("\" ");
106 out.write(toAttr(dyn));
107 out.write(">");
108 out.write(CubbyFunctions.out(value));
109 out.write("</textarea>\n");
110 }
111 }