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