For Programmers: Free Programming Magazines  


Home > Archive > Java Help > January 2007 > Custom Tag lib life-cycle question.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Custom Tag lib life-cycle question.
Daniel Pitts

2007-01-22, 7:08 pm

So, I've created a tag which takes an optional attribute. It seems to
be retaining the value of the attribute between invocations of the tag.


--- CUT -- MyTag.java -- CUT ---
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspException;


public class MyTag extends TagSupport {
private Object myArgument;
private static int counter = 0;
public int doStartTag() throws JspException {
if (myArgument == null) {
myArgument = new Integer(++counter);
}
try {
pageContext.getOut().print(myArgument);
} catch (Exception e) {
throw new JspException(e);
}
return SKIP_BODY;
}
public int doEndTag() throws JspException {
return EVAL_PAGE;
}

public Object getMyArgument() {
return myArgument;
}

public void setMyArgument(Object myArgument) {
this.myArgument = myArgument;
}
}
--- END -- MyTag.java -- END ---

In my JSP I have:
<mytags:myTag />
<mytags:myTag />
<mytags:myTag myArgument="help" />

I would expect the output to be
1
2
help
but the output is
1
1
help

My question is, where is the appropriate location to reset the
myArgument reference? at doEndTag? release? somewhere else?

Or, am I going about this the wrong way altogether? Keeping in mind
this is a simplified version of my actual usecase.

Thanks,
Daniel.

(x-posted to comp.lang.java.(programmer/help/gui), follow-up to
programmer)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com