01: package example.taglib;
02:
03: import javax.servlet.jsp.*;
04: import javax.servlet.jsp.tagext.*;
05:
06: public class MessageAddTag extends TagSupport {
07: /* tag attributes */
08: String _text;
09:
10: /* internal member variables */
11: MessageTag _parentTag;
12:
13: public void setText(String text) {
14: _text = text;
15: }
16:
17: public int doStartTag() throws JspException {
18: // initialize internal member variables
19: init();
20:
21: _parentTag.addToMessage(_text);
22:
23: return SKIP_BODY;
24: }
25:
26: private void init() throws JspException {
27: _parentTag = (MessageTag) findAncestorWithClass(this ,
28: MessageTag.class);
29: if (_parentTag == null)
30: throw new JspException("Could not find parent MessageTag");
31: }
32: }
|