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.getOutputValues; |
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 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 5 | public class TextareaTag extends DynamicAttributesTagSupport { |
41 | |
|
42 | |
private String name; |
43 | |
|
44 | |
private Object value; |
45 | |
|
46 | |
private Integer index; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public void setName(final String name) { |
55 | 4 | this.name = name; |
56 | 4 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public void setValue(final Object value) { |
65 | 1 | this.value = value; |
66 | 1 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public void setIndex(final Integer index) { |
75 | 0 | this.index = index; |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
@Override |
82 | |
public void doTag() throws JspException, IOException { |
83 | 4 | final JspContext context = this.getJspContext(); |
84 | 4 | final JspWriter out = context.getOut(); |
85 | 4 | final ActionErrors errors = errors(context); |
86 | 4 | final Map<String, Object> dyn = this.getDynamicAttribute(); |
87 | 4 | final String[] outputValues = getOutputValues(this, this.name); |
88 | |
|
89 | 4 | if (this.index == null) { |
90 | 4 | if (!errors.getFields().get(this.name).isEmpty()) { |
91 | 0 | addClassName(dyn, "fieldError"); |
92 | |
} |
93 | |
} else { |
94 | 0 | if (!errors.getIndexedFields().get(this.name).get(this.index) |
95 | |
.isEmpty()) { |
96 | 0 | addClassName(dyn, "fieldError"); |
97 | |
} |
98 | |
} |
99 | 4 | final Object value = formValue(context, outputValues, this.name, |
100 | |
this.index, this.value); |
101 | |
|
102 | 4 | out.write("<textarea name=\""); |
103 | 4 | out.write(this.name); |
104 | 4 | out.write("\" "); |
105 | 4 | out.write(toAttr(dyn)); |
106 | 4 | out.write(">"); |
107 | 4 | out.write(CubbyFunctions.out(value)); |
108 | 4 | out.write("</textarea>"); |
109 | 4 | } |
110 | |
} |