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