01: package com.mockrunner.example.tag;
02:
03: import java.io.IOException;
04:
05: import javax.el.ValueExpression;
06: import javax.servlet.jsp.JspException;
07: import javax.servlet.jsp.tagext.SimpleTagSupport;
08:
09: /**
10: * This tag renders an HTMl text input field with the provided
11: * name and value. The value is determined using a deferred value
12: * expression.
13: */
14: public class HtmlTextTag extends SimpleTagSupport {
15: private String name;
16: private ValueExpression value;
17:
18: public String getName() {
19: return name;
20: }
21:
22: public void setName(String name) {
23: this .name = name;
24: }
25:
26: public ValueExpression getValue() {
27: return value;
28: }
29:
30: public void setValue(ValueExpression value) {
31: this .value = value;
32: }
33:
34: public void doTag() throws JspException, IOException {
35: StringBuffer html = new StringBuffer();
36: html.append("<input type=\"text\" ");
37: html.append("name=\"");
38: html.append(name);
39: html.append("\" ");
40: html.append("value=\"");
41: html.append(value.getValue(getJspContext().getELContext()));
42: html.append("\"");
43: html.append("/>");
44: getJspContext().getOut().print(html.toString());
45: }
46: }
|