View Javadoc

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