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