aspose file tools*
The moose likes JSP and the fly likes Cleaning Instance Variables for Tags in Tomcat4.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Cleaning Instance Variables for Tags in Tomcat4.1" Watch "Cleaning Instance Variables for Tags in Tomcat4.1" New topic
Author

Cleaning Instance Variables for Tags in Tomcat4.1

Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi,
This class creates the image buttons dynamically like button1,button2 and so on with onMouseOver functionality.
In tomcat4.1, the instance variables are giving sort of error like they are not getting incremented,its may be
b/c the instance variables are not properly cleaned up for reuse of tags.

i checked out the View Source of the HTML ,it looks ok except that the getImageName() , getSrc() and getOnSrc() functions
are printing the same value all the time ..
eg button1
button1 ....

Can any one help me out ,why the instance variables are not getting cleaned up after the tag usage..



public class ToggleButtonLink extends LinkTag
{
private static Category cat = WebServerCategory.getInstance(" ToggleButtonLink ");

public ToggleButtonLink()
{
src = null;
onSrc = null;
first = true;
imageName = null;
results = new StringBuffer();
}

public String getSrc()
{
return src;
}

public void setSrc(String src)
{
this.src = src;
}

public String getOnSrc()
{
return onSrc;
}

public void setOnSrc(String onSrc)
{
this.onSrc = onSrc;
}

public String getImageName()
{
return imageName;
}

private void createImageName()
{
counter = (Integer)super.pageContext.getAttribute("imageCounter");
if(counter == null)
counter = new Integer(0);
next = new Integer(counter.intValue() + 1);
super.pageContext.setAttribute("imageCounter", next);
imageName = "button" + next.toString();
}

protected static String concat(String s1, String s2)
{
if(s1 == null)
return s2;
if(s2 == null)
return s1;
else
return s1 + ";" + s2;
}

public int doStartTag()
throws JspException
{
if(getOnSrc() == null)
setOnSrc(getSrc().substring(0, getSrc().length() - 5) + "2.gif");
createImageName();
if(first)
{
setOnmouseover(concat("document.images['" + getImageName() + "'].src='" + getOnSrc() + "'", getOnmouseover()));
setOnmouseout(concat("document.images['" + getImageName() + "'].src='" + getSrc() + "'", getOnmouseout()));
first = false;
}
reply = super.doStartTag();
results = new StringBuffer("<img name=\"" + getImageName() + "\" src=" + getSrc() + " border=\"0\">");
cat.debug("Result String = " + results.toString() );
ResponseUtils.write(super.pageContext, results.toString());
return reply;
}

private String src;
private String onSrc;
private String imageName;
boolean first;
private int reply ;
private StringBuffer results;
private Integer counter ;
private Integer next;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cleaning Instance Variables for Tags in Tomcat4.1