Tag lifecycle with Attribute : Tag « JSP « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » JSP » TagScreenshots 
Tag lifecycle with Attribute


  <!-- this must be added to the web application's web.xml -->

<taglib>
  <taglib-uri>/java2s</taglib-uri>
  <taglib-location>/WEB-INF/java2s.tld</taglib-location>
</taglib>

// create File:java2s.tld in the /WEB-INF/
<!DOCTYPE taglib
  PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
   "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

    <!-- a tab library descriptor -->
<taglib xmlns="http://java.sun.com/JSP/TagLibraryDescriptor">
  <tlib-version>1.0</tlib-version>
  <jsp-version>1.2</jsp-version>
  <short-name>Java2s Simple Tags</short-name>


  <!-- a tag that outputs information when different methods are called -->
  <tag>
    <name>tagLifecycle</name>
    <tag-class>com.java2s.TagLifecycle</tag-class>
    <body-content>empty</body-content>
    <attribute>
      <name>attr1</name>
    </attribute>
    <attribute>
      <name>attr2</name>
    </attribute>
  </tag>

</taglib>
//compile the following code into WEB-INF\classes\com\java2s
package com.java2s;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

/* This tag handler outputs information about when different methods
   are called in the Tag interface.
 */

public class TagLifecycle extends TagSupport
{
  // Constructor

  public TagLifecycle()
  {
    System.out.println("TagLifecycle constructor called");
  }

  // Methods inherited from TagSupport

  public void setPageContext(PageContext p)
  {
    super.setPageContext(p);
    System.out.println("setPageContext() called (" + p + ")");
  }
  
  public void setParent(Tag t)
  {
    super.setParent(t);
    System.out.println("setParent() called (" + t + ")");
  }

  public Tag getParent()
  {
    System.out.println("getParent() called");
    return super.getParent();
  }
  
  public void release()
  {
    System.out.println("release() called");
  }
  
  // Code to implement the "attr1" attribute

  private String attr1;
  public String getAttr1()
  {
    return attr1;
  }
  public void setAttr1(String s)
  {
    System.out.println("setAttr1() called with value " + s);
    attr1 = s;
  }

  // Code to implement the "attr2" attribute

  private String attr2;
  public String getAttr2()
  {
    return attr2;
  }
  public void setAttr2(String s)
  {
    System.out.println("setAttr2() called with value " + s);
    attr2 = s;
  }

  public int doStartTag() throws JspException
  {
    System.out.println("doStartTag() called");

    return SKIP_BODY;
  }

  public int doEndTag() throws JspException
  {
    System.out.println("doEndTag() called");
    return super.doEndTag();
  }
}



// start comcat and load the following jsp page in browser
<%@ taglib uri="/java2s" prefix="java2s" %>

<html>
  <head>
    <title>The lifecycle of the Tag interface</title>
  </head>
  <body>
    <java2s:tagLifecycle attr1="Joe" attr2="Greenhough" />
    <java2s:tagLifecycle attr1="Rob" attr2="Greenhough" />

    Check the Tomcat console for the output
  </body>
</html>




           
       
Related examples in the same category
1. Your own simple JSP tag
2. Create your own tag: a custom tag body
3. A custom tag that has neither attributes nor body content.
4. A custom tag: empty with attributes
5. A custom tag: scripting variable
6. Write your own tag
7. Logo Tag
8. A custom tag: empty
9. A custom tag: iteration
10. JSP Simple Tags
11. JSP tag: advanced tagsJSP tag: advanced tags
12. JSP classic tagsJSP classic tags
13. JSP Tag Libraries and JSTLJSP Tag Libraries and JSTL
14. JSP Directives: HTML tag
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.