View Javadoc

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  public class FormTag extends BodyTagSupport implements DynamicAttributes {
16  	
17  	private static final long serialVersionUID = 3997441280451382093L;
18  
19  	private Map<String, Object>  dyn = new HashMap<String, Object>();
20  
21  	private Object value;
22  	
23  	public void setDynamicAttribute(final String uri, final String localName, final Object value)
24  	throws JspException {
25  		this.dyn.put(localName, value);
26  	}
27  	
28  	protected Map<String, Object> getDynamicAttribute() {
29  		return this.dyn;
30  	}
31  	
32  	public void setValue(final Object value) {
33  		this.value = value;
34  	}
35  
36  	@Override
37  	public int doStartTag() throws JspException {
38  		pageContext.setAttribute("__form", value, PageContext.REQUEST_SCOPE);
39  		JspWriter out = pageContext.getOut();
40  		try {
41  			out.write("<form ");
42  			out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute()));
43  			out.write(">\n");
44  		} catch (IOException e) {
45  			throw new JspException(e);
46  		}
47  		return EVAL_BODY_INCLUDE;
48  	}
49  
50  	@Override
51  	public int doEndTag() throws JspException {
52  		try {
53  			pageContext.getOut().write("</form>\n");
54  		} catch (IOException e) {
55  			throw new JspException(e);
56  		}
57  		pageContext.removeAttribute("__form", PageContext.REQUEST_SCOPE);
58  		return EVAL_PAGE;
59  	}
60  }