aspose file tools*
The moose likes JSP and the fly likes Custom Tags - Repeating Tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom Tags - Repeating Tags " Watch "Custom Tags - Repeating Tags " New topic
Author

Custom Tags - Repeating Tags

Lakshmi Anantharaman
Ranch Hand

Joined: Aug 01, 2001
Posts: 58
Hi .
I am so intrigued :eek by this behaviour . Obviously I am missing something .
When repeating tags ina JSP page why does it process only once .
To make my self clear
//*********************************************
<%@ taglib uri="/WEB-INF/tlds/hello.tld"
prefix="test" %>
<HTML>
<HEAD>
<TITLE>Hello Tag</TITLE>
</HEAD>
<BODY bgcolor="#ffffcc">
<test:hello />
<test:hello />
<test:hello />
</BODY>
</HTML>
only prints the output one and behaves just the same as
<%@ taglib uri="/WEB-INF/tlds/hello.tld"
prefix="test" %>
<HTML>
<HEAD>
<TITLE>Hello Tag</TITLE>
</HEAD>
<BODY bgcolor="#ffffcc">
<test:hello />
</BODY>
</HTML>
//*******************************************
This is not the case for looping body Tags
can any one explain Why
Thanks and Regards
Lakshmi

Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
I'm not quite sure what's happening here ... are you returning SKIP_PAGE from your doEndTag method?
Simon
------------------
Simon Brown
Co-author of Professional JSP 2nd Edition
Lakshmi Anantharaman
Ranch Hand

Joined: Aug 01, 2001
Posts: 58
Thanks for the response ,
Yes , I do have doEndTag() returning SKIP_PAGE !
I am able to reproduce this behaviour in many simple tags that I created .
If I have the tags repeated in my JSP page it is processed only once .
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Hi Lakshmi,
There are two valid return values for doEndTag - SKIP_PAGE and EVAL_PAGE.
(1) SKIP_PAGE tells the JSP to skip (ignore) the rest of the page entirely. This is what is happening here - in other words nothing after the first tag is being processed.
(2) EVAL_PAGE tells the JSP to carry on processing the page. This is the usual return value for the majority of the tags that we write.
Changing the doEndTag to return EVAL_PAGE will fix your problems.
Hope that helps...
Simon
------------------
Simon Brown
Co-author of Professional JSP 2nd Edition
Lakshmi Anantharaman
Ranch Hand

Joined: Aug 01, 2001
Posts: 58
All my doEndTag() for simple tags ( other than the iteration tags with Body) did return SKIP_PAGE. But changing them to EVAL_PAGE (sounded like what was wrong ) did not help me.
My TagHandler Class looks like this .
/******************************************************
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class HelloTagSupport extends TagSupport {
private String name;
public void setName(String name)
{
this.name=name;
}
public int doStartTag() throws JspException {
try {
pageContext.getOut().println(" Using the Tag Support Interface "+name);

} catch (IOException ioe) {
throw new JspException("Error: IOException while writing to client" + ioe.getMessage());
}
return SKIP_BODY;
}
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
}
********************************************/
In my tag library descriptor(hello.tld) I have a list of tags. Is this something wrong ?
My Tld
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<!-- a tag library descriptor -->
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>first</shortname>
<uri></uri>
<info>A simple tab library for the
examples</info>
<tag>
<name>hello</name>
<tagclass>com.adspedia.gui.framework.tags.HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Say Hi</info>
</tag>
<tag>
<name>helloSupport</name>
<tagclass>com.adspedia.gui.framework.tags.HelloTagSupport</tagclass>
<bodycontent>empty</bodycontent>
<info>Tag with Parameter</info>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>

<tag>
<name>tolowercase</name>
<tagclass>com.adspedia.gui.framework.tags.ToLowerCaseTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>To lower case tag</info>
</tag>
<tag>
<name>loop</name>
<tagclass>com.adspedia.gui.framework.tags.LoopTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>Tag with body and parameter</info>
<attribute>
<name>times</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
In my JSP page I use the same prefix for all these tags .
Lakshmi
Appreciate your time .
Lakshmi
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
So what's the problem now ... is the rest of the page still being skipped?
Simon
------------------
Simon Brown
Co-author of Professional JSP 2nd Edition
Lakshmi Anantharaman
Ranch Hand

Joined: Aug 01, 2001
Posts: 58
I do not not why but it worked. probably because of the EVAL_PAGE returned by the doEndTag(). Thanks Simon . I have made steady progress with the custom Tags. I also have a copy of your book with me .
Lakshmi
----------------------------------------------------------------
Originally posted by Simon Brown:
So what's the problem now ... is the rest of the page still being skipped?
Simon

 
 
subject: Custom Tags - Repeating Tags