You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Thielen <da...@windward.net> on 2003/03/23 06:46:23 UTC

iterative taglib weirdness

Hi;

I am writing an iterative taglib where I have a variable assigned to id that can then be accessed as <%=id%> inside the taglib loop. The thing is, the first time through the loop id is null. The second+ times it is the second+ values.

Any ideas?

thanks - dave


My code is:

List titles;
ListIterator li;

public int doStartTag() {
  
    readStringsIntoTitles();
  
    if (titles.size() == 0)
        return SKIP_BODY;

    li = titles.listIterator(); 
    pageContext.setAttribute( id, li.next() );
    return EVAL_BODY_INCLUDE;
}
 
 public int doAfterBody() throws JspException {

    // handle if have more
    if (li.hasNext()) {
        pageContext.setAttribute( id, li.next() );
        return EVAL_BODY_AGAIN;
    }

    // all done
    return SKIP_BODY;
}