Q1) Please explain how tag can call its parent tag?
Q2) Please find the code that i tried to implement it. Please correct it?
------------------------------
JSP CODE
<code>
<%--
Document : index
Created on : Sep 26, 2009, 2:12:01 PM
Author : satyajit
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/Sample" prefix="mine" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<mine:OuterTag>
<mine:InnerTag/>
</mine:OuterTag>
</body>
</html>
</code>
TLD CODE
<code>
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>sample</short-name>
<uri>/WEB-INF/Sample</uri>
<tag>
<name>InnerTag</name>
<tag-class>Tag.InnerTag</tag-class>
<body-content>scriptless</body-content>
</tag>
<tag>
<name>OuterTag</name>
<tag-class>Tag.OuterTag</tag-class>
<body-content>scriptless</body-content>
</tag>
</taglib>
</code>
InnerTag.java code
<code>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Tag;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
/**
*
* @author satyajit
*/
public class InnerTag extends SimpleTagSupport
{
public void doTag() throws JspException,IOException
{
getJspContext().getOut().print("inside to tag of Inner tag");
OuterTag outertag=(OuterTag)getParent();
getJspContext().getOut().println("outertag tag is"+outertag.toString());
}
}
</code>
OuterTAG.java code
<code>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Tag;
import javax.servlet.jsp.*;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class OuterTag extends SimpleTagSupport {
public void doTag() throws JspException,IOException
{
getJspContext().getOut().print("outer tag");
// InnerTag innertag=(InnerTag)getParent();
// getJspContext().getOut().print(innertag.toString());
}
}
</code>