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