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-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  
  */
 40  4
 public class TextareaTag extends DynamicAttributesTagSupport {
 41  
 
 42  
         private String name;
 43  
 
 44  
         private Object value;
 45  
 
 46  
         private Integer index;
 47  
 
 48  
         public void setName(final String name) {
 49  4
                 this.name = name;
 50  4
         }
 51  
 
 52  
         public void setValue(final Object value) {
 53  1
                 this.value = value;
 54  1
         }
 55  
 
 56  
         public void setIndex(final Integer index) {
 57  0
                 this.index = index;
 58  0
         }
 59  
 
 60  
         /**
 61  
          * タグの処理
 62  
          */
 63  
         @Override
 64  
         public void doTag() throws JspException, IOException {
 65  4
                 final JspContext context = this.getJspContext();
 66  4
                 final JspWriter out = context.getOut();
 67  4
                 final ActionErrors errors = errors(context);
 68  4
                 final Map<String, Object> dyn = this.getDynamicAttribute();
 69  4
                 final Map<String, String[]> outputValues = outputValues(context);
 70  
 
 71  4
                 if (this.index == null) {
 72  4
                         if (!errors.getFields().get(this.name).isEmpty()) {
 73  0
                                 addClassName(dyn, "fieldError");
 74  
                         }
 75  
                 } else {
 76  0
                         if (!errors.getIndexedFields().get(this.name).get(this.index)
 77  
                                         .isEmpty()) {
 78  0
                                 addClassName(dyn, "fieldError");
 79  
                         }
 80  
                 }
 81  4
                 final Object value = formValue(context, outputValues, this.name,
 82  
                                 this.index, this.value);
 83  
 
 84  4
                 out.write("<textarea name=\"");
 85  4
                 out.write(this.name);
 86  4
                 out.write("\" ");
 87  4
                 out.write(toAttr(dyn));
 88  4
                 out.write(">");
 89  4
                 out.write(CubbyFunctions.out(value));
 90  4
                 out.write("</textarea>\n");
 91  4
         }
 92  
 }