01: package com.mockrunner.example.tag;
02:
03: import javax.servlet.jsp.JspException;
04:
05: import org.apache.struts.taglib.html.TextTag;
06:
07: /**
08: * This example tag extends the Struts <code>TextTag</code>
09: * and adds a JavaScript handler for checking numeric constraints.
10: * Have a look at {@link ConstrainedNumericTextTagTest} to see
11: * how to test simple tags.
12: */
13: public class ConstrainedNumericTextTag extends TextTag {
14: private int minValue = 0;
15: private int maxValue = Integer.MAX_VALUE;
16:
17: public int getMaxValue() {
18: return maxValue;
19: }
20:
21: public int getMinValue() {
22: return minValue;
23: }
24:
25: public void setMaxValue(int maxValue) {
26: this .maxValue = maxValue;
27: }
28:
29: public void setMinValue(int minValue) {
30: this .minValue = minValue;
31: }
32:
33: public void release() {
34: super .release();
35: minValue = 0;
36: maxValue = Integer.MAX_VALUE;
37: }
38:
39: public int doStartTag() throws JspException {
40: setOnblur(createJavaScriptHandler());
41: return super .doStartTag();
42: }
43:
44: private String createJavaScriptHandler() {
45: StringBuffer handler = new StringBuffer();
46: handler.append("checkConstraints(");
47: handler.append("this,");
48: handler.append(getMinValue() + ",");
49: handler.append(getMaxValue() + ");");
50: if (null != getOnblur())
51: handler.append(getOnblur());
52: return handler.toString();
53: }
54: }
|