View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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   * textareaを出力するタグ
36   * 
37   * @author agata
38   * @author baba
39   * @since 1.0.0
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  	 * name属性を設定します。
51  	 * 
52  	 * @param name
53  	 *            name属性
54  	 */
55  	public void setName(final String name) {
56  		this.name = name;
57  	}
58  
59  	/**
60  	 * value属性を設定します。
61  	 * 
62  	 * @param value
63  	 *            value属性
64  	 */
65  	public void setValue(final Object value) {
66  		this.value = value;
67  	}
68  
69  	/**
70  	 * index属性を設定します。
71  	 * 
72  	 * @param index
73  	 *            index属性
74  	 */
75  	public void setIndex(final Integer index) {
76  		this.index = index;
77  	}
78  
79  	/**
80  	 * {@inheritDoc}
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 }