View Javadoc

1   package org.seasar.cubby.tags;
2   
3   import java.io.IOException;
4   import java.util.Map;
5   
6   import javax.servlet.jsp.JspException;
7   import javax.servlet.jsp.JspWriter;
8   import javax.servlet.jsp.PageContext;
9   
10  import org.seasar.cubby.util.CubbyHelperFunctions;
11  
12  public class InputTag extends DynamicAttributesTagSupport {
13  	
14  	private String type;
15  	
16  	public String getType() {
17  		return type;
18  	}
19  
20  	public void setType(final String type) {
21  		this.type = type;
22  	}
23  
24  	@SuppressWarnings("unchecked")
25  	@Override
26  	public void doTag() throws JspException, IOException {
27  		final Map fieldErros = (Map) getJspContext().getAttribute("fieldErrors", PageContext.REQUEST_SCOPE);
28  		if (fieldErros.get(getDynamicAttribute().get("name")) != null) {
29  			CubbyHelperFunctions.addClassName(getDynamicAttribute(), "fieldError");
30  		}
31  
32  		final JspWriter out = getJspContext().getOut();
33  		final Object form = getJspContext().getAttribute("__form", PageContext.REQUEST_SCOPE);
34  		if ("checkbox".equals(type)) {
35  			final String value = toString(getDynamicAttribute().get("value"));
36  			final Object checkedValue = CubbyHelperFunctions.formValue2(getDynamicAttribute(), form, getJspContext(), "checkedValue");
37  			getJspContext().setAttribute("value", value, PageContext.PAGE_SCOPE);
38  			getJspContext().setAttribute("checkedValue", checkedValue, PageContext.PAGE_SCOPE);
39  			out.write("<input type=\"");
40  			out.write(type);
41  			out.write("\" value=\"");
42  			out.write(value);// TODO
43  			out.write("\" ");
44  			out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute()));
45  			out.write(" ");
46  			out.write(CubbyHelperFunctions.checked(value, checkedValue));
47  			out.write("/>\n");
48  		} else {
49  			final Object value = CubbyHelperFunctions.formValue2(getDynamicAttribute(), form, getJspContext(), "value");
50  			final Object checkedValue = getDynamicAttribute().get("checkedValue");
51  			getJspContext().setAttribute("value", value, PageContext.PAGE_SCOPE);
52  			getJspContext().setAttribute("checkedValue", checkedValue, PageContext.PAGE_SCOPE);
53  			out.write("<input type=\"");
54  			out.write(type);
55  			out.write("\" value=\"");
56  			out.write(CubbyHelperFunctions.convertFieldValue(value, form, getRequest(), toString(getDynamicAttribute().get("value"))));// TODO
57  			out.write("\" ");
58  			out.write(CubbyHelperFunctions.toAttr(getDynamicAttribute()));
59  			out.write("/>\n");
60  		}
61  	}
62  }