aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes A tag can call its parent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "A tag can call its parent" Watch "A tag can call its parent" New topic
Author

A tag can call its parent

Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
Q1) Please how tag can call its parent tag?
Q2) I tried to implement it b
Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
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>
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Amol please Use Code Tags when you post a source code. You can edit your message using button and then add code tags to it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

The normal HTML <code></code> tag doesn't work here, use [code][/code] tags instead. There is a button in the editor to help you with that...
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 460

amolpalekar kadolkar wrote:Q1) Please explain how tag can call its parent tag?
Q2) Please find the code that i tried to implement it. Please correct it?


The code seems to be correct to me. Are you getting any exception with this code?
If you can tell me exactly what you are getting (errors etc) I may be able to tell you

Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A tag can call its parent