• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

A tag can call its parent

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1) Please how tag can call its parent tag?
Q2) I tried to implement it b
 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 463
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic