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 | 4 | 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 | 4 | this.name = name; |
57 | 4 | } |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void setValue(final Object value) { |
66 | 1 | this.value = value; |
67 | 1 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public void setIndex(final Integer index) { |
76 | 0 | this.index = index; |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Override |
83 | |
public void doTag() throws JspException, IOException { |
84 | 4 | final JspContext context = this.getJspContext(); |
85 | 4 | final JspWriter out = context.getOut(); |
86 | 4 | final ActionErrors errors = errors(context); |
87 | 4 | final Map<String, Object> dyn = this.getDynamicAttribute(); |
88 | 4 | final Map<String, String[]> outputValues = outputValues(context); |
89 | |
|
90 | 4 | if (this.index == null) { |
91 | 4 | if (!errors.getFields().get(this.name).isEmpty()) { |
92 | 0 | addClassName(dyn, "fieldError"); |
93 | |
} |
94 | |
} else { |
95 | 0 | if (!errors.getIndexedFields().get(this.name).get(this.index) |
96 | |
.isEmpty()) { |
97 | 0 | addClassName(dyn, "fieldError"); |
98 | |
} |
99 | |
} |
100 | 4 | final Object value = formValue(context, outputValues, this.name, |
101 | |
this.index, this.value); |
102 | |
|
103 | 4 | out.write("<textarea name=\""); |
104 | 4 | out.write(this.name); |
105 | 4 | out.write("\" "); |
106 | 4 | out.write(toAttr(dyn)); |
107 | 4 | out.write(">"); |
108 | 4 | out.write(CubbyFunctions.out(value)); |
109 | 4 | out.write("</textarea>\n"); |
110 | 4 | } |
111 | |
} |