Write your own custom tag library operating principle (4)

By reading the three articles before, already can handle your own custom tag libraries, but if not familiar with the operation principle of custom tag, if you encounter an error may be confused, this article will introduce the operation principle of custom tag.

1.JspTag Interface

Achieved the previous instance TagSupport class, and there is no direct use JspTag interface, but in fact tag handling class must be achieved JspTag interfaces. JspTag interface definition in javax.servlet.jsp.tagext package, it is just a marking interface does not define any methods, all tag handling class must implement this interface.

javax.servlet.jsptagext package also includes IterationTag interfaces, BodyTag interfaces, SimpleTag interfaces, TagSupport class, BodyTagSupport class and simpleTagSupport class, inheritance relation between them is as follows:

JspTag Interface

|

----------- Tag Interface

| |

| ---------- IterationTag Interface

| |

| --------------------- TagSupport class

| | |

| ---------------- BodyTag Interface |

| | |

| --------- BodyTagSupport class

|

----------- SimpleTag Interface

|

-------- SimpleTagSupport class

Tag interface:

This interface defines the write tag address classes to achieve the basic methods, including what methods: doStartTag (), doEndTag (), getParent (), release () and setPageContext () method, which doStartTag () and doEndTag () method is the most commonly used method. doStartTag () method in the implementation of the custom tag is called when the start tag, doEndTag () method in the implementation of the custom tag's end tag is called.

Tag in the actual preparation of the class when dealing with the general without directly implement this interface, usually inherit this interface has been achieved or BodyTagSupport TagSupport class.

IterationTag interface:

This interface inherits from the Tag interface and adds a new doAfterBody () method, this method can generally achieve the contents of custom tag that contains the cycle of operation.

doAfterBody () method only if the doStartTag () method returns a value of EVAL_BODY_INCLUDE only when called. Call doAfterBody () method, if the return value is EVAL_BODY_AGAIN, it will again run the custom tag that contains the content and once again call doAfterBody () method until the doAfterBody () method returns a value of SKIP_BODY, so that to realize the custom tag contains operational content.

TagSupport categories:

This class is the most commonly used preparation of custom tag class, in fact it is a helper class that can help us to quickly write tag handler class, he realized IterationTag interfaces. We write tag handler class can inherit the class time, rewrite the way they need, without the need to directly interface to achieve IterationTag or Tag. The design model used here the default adapter mode.

An inherited class that TagSupport tag handling custom tag this tag can display the content contained, but can not edit the contents contained in and transform. If you need to edit the contents contained in the need to inherit BodyTagSupport class

TagSupport class call process is as follows:
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Write your own custom tag library operating principle (4)

  • js page Jump implementation of a number of ways

    The first is: <script language="javascript" type="text/javascript"> window.location.href = "login.jsp? backurl =" + window.location.href; </ script> The second: <script language="javascript"> alert

  • In the Spring to configure Service

    JTA in Spring Development Environment: JDK1.5 (sun) + Myeclipse6.0 + Tomcat5.5 + ant 1.7.1 + MySql5.0.4 Framework version: JSF1.2 (sun) + hibernate3.3.1.GA + spring2.5.6 JTA (Java Transaction API) Only supports the standard EJB Persistence (JTA) transacti

  • Dynamic loading JS script four kinds of methods

    To achieve dynamic loading JS script has four kinds of methods: 1, direct document.write <script language="javascript"> document.write ( "<script src='test.js'> <\ / script>"); </ script> 2, dynamic scri

  • Hibernate primary key strategy-sequence

    Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...

  • Hibernate pessimistic locking mechanism for locking and optimistic locking

    hibernate lock mechanism 1. Pessimistic lock It refers to the modification of data by outsiders hold a conservative attitude. The assumption that at any time access to data, may also have another client to access the same data, in order to maintain t ...

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries