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 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 3 | public class FormTag extends BodyTagSupport implements DynamicAttributes { |
25 | |
|
26 | |
private static final long serialVersionUID = 3997441280451382093L; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 3 | private Map<String, Object> attrs = new HashMap<String, Object>(); |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
private Object value; |
37 | |
|
38 | |
|
39 | |
|
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 | |
|
48 | |
|
49 | |
|
50 | |
protected Map<String, Object> getDynamicAttribute() { |
51 | 3 | return this.attrs; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
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 | |
} |