Chapter 11. New Tag Library Features in JSP 1.2

Topics in This Chapter

  • Converting TLD files to the new format

  • Bundling life-cycle event listeners with tag libraries

  • Checking custom tag syntax with TagLibraryValidator

  • Using the Simple API for XML (SAX) in validators

  • Handling errors with the TryCatchFinally interface

  • Changing names of method return values

  • Looping without creating BodyContent

  • Declaring scripting variables in the TLD file

Section 3.7 (Defining Custom JSP Tag Libraries) describes the creation and use of tag libraries in JSP 1.1. You do not need to modify JSP 1.1 tag libraries to make them work in JSP 1.2; they are totally compatible. However, JSP 1.2 has a number of new capabilities that are unavailable in JSP 1.1. Tag libraries that use these new capabilities must use a slightly different format for the TLD file. This chapter first describes that new format and then explains the use of each of the new capabilities. The following list gives a brief summary; details are provided in the following sections.

  • New TLD format. The DOCTYPE definition has changed, some existing elements have been renamed (mostly by the addition of dashes), and several new elements have been introduced.

  • Ability to bundle listeners with tag libraries. The servlet 2.3 specification introduced application life-cycle listeners. The JSP 1.2 specification added the ability to bundle these listeners with tag libraries.

  • TagLibraryValidator for translation-time syntax checking. JSP 1.2 permits you to create a class that, at page translation time, can read an entire JSP file (represented in XML) and check that the custom tags are used properly.

  • TryCatchFinally interface. JSP 1.2 introduced a new interface with two methods: doCatch and doFinally. These methods help tags handle uncaught exceptions that occur in any of the tag life-cycle methods or during the processing of the tag body.

  • New return values. In JSP 1.1, EVAL_BODY_TAG was used in two distinct situations. In JSP 1.2, the constant is replaced with EVAL_BODY_BUFFERED and EVAL_BODY_AGAIN to better differentiate the two cases.

  • Looping without creating BodyContent. In JSP 1.1, iteration-related tags extended BodyTagSupport and returned EVAL_BODY_TAG from doAfterBody to indicate that the tag body should be reevaluated and made available in a BodyContent object. In JSP 1.2, you can extend TagSupport and return EVAL_BODY_AGAIN to indicate that the body should be reevaluated and sent to the client with no intervening BodyContent. This yields an implementation that is easier to read and more efficient.

  • The variable element for introducing scripting variables. Instead of declaring variables only in the TagExtraInfo class, JSP 1.2 lets you declare them in the TLD file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.223.168