Coverage Report - org.seasar.cubby.tags.FormTag
 
Classes in this File Line Coverage Branch Coverage Complexity
FormTag
100%
18/18
N/A
0
 
 1  
 package org.seasar.cubby.tags;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.util.HashMap;
 5  
 import java.util.Map;
 6  
 
 7  
 import javax.servlet.jsp.JspException;
 8  
 import javax.servlet.jsp.JspWriter;
 9  
 import javax.servlet.jsp.PageContext;
 10  
 import javax.servlet.jsp.tagext.BodyTagSupport;
 11  
 import javax.servlet.jsp.tagext.DynamicAttributes;
 12  
 
 13  
 import org.seasar.cubby.util.CubbyHelperFunctions;
 14  
 
 15  
 /**
 16  
  * フォー?を?力するタグライブラリ?
 17  
  * <p>
 18  
  * {@link InputTag}, {@link SelectTag}, {@link TextareaTag}を保持することができます??
 19  
  * </p>
 20  
  * FIXME 親子関係?仕?みを改?した?。現在は__form決めうち
 21  
  * @author agata
 22  
  * 
 23  
  */
 24  3
 public class FormTag extends BodyTagSupport implements DynamicAttributes {
 25  
 
 26  
         private static final long serialVersionUID = 3997441280451382093L;
 27  
 
 28  
         /**
 29  
          * DynamicAttributes
 30  
          */
 31  3
         private Map<String, Object> attrs = new HashMap<String, Object>();
 32  
 
 33  
         /**
 34  
          * フォー?のバイン?ィング対象のBean
 35  
          */
 36  
         private Object value;
 37  
 
 38  
         /**
 39  
          * DynamicAttributeをセ?トします??
 40  
          */
 41  
         public void setDynamicAttribute(final String uri, final String localName,
 42  
                         final Object value) throws JspException {
 43  3
                 this.attrs.put(localName, value);
 44  3
         }
 45  
 
 46  
         /**
 47  
          * DynamicAttributeを取得します??
 48  
          * @return DynamicAttribute
 49  
          */
 50  
         protected Map<String, Object> getDynamicAttribute() {
 51  3
                 return this.attrs;
 52  
         }
 53  
 
 54  
         /**
 55  
          * フォー?のバイン?ィング対象のBeanをセ?トします??
 56  
          * @param value フォー?のバイン?ィング対象のBean
 57  
          */
 58  
         public void setValue(final Object value) {
 59  3
                 this.value = value;
 60  3
         }
 61  
 
 62  
         /**
 63  
          * 開始タグ
 64  
          */
 65  
         @Override
 66  
         public int doStartTag() throws JspException {
 67  3
                 pageContext.setAttribute("__form", value, PageContext.REQUEST_SCOPE);
 68  3
                 JspWriter out = pageContext.getOut();
 69  
                 try {
 70  3
                         out.write("<form ");
 71  3
                         out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute()));
 72  3
                         out.write(">\n");
 73  
                 } catch (IOException e) {
 74  
                         throw new JspException(e);
 75  3
                 }
 76  3
                 return EVAL_BODY_INCLUDE;
 77  
         }
 78  
 
 79  
         /**
 80  
          * 終?タグ
 81  
          */
 82  
         @Override
 83  
         public int doEndTag() throws JspException {
 84  
                 try {
 85  3
                         pageContext.getOut().write("</form>\n");
 86  
                 } catch (IOException e) {
 87  
                         throw new JspException(e);
 88  3
                 }
 89  3
                 pageContext.removeAttribute("__form", PageContext.REQUEST_SCOPE);
 90  3
                 return EVAL_PAGE;
 91  
         }
 92  
 }