22. Using Third-Party Tag Libraries

PROBLEM

Java EE provides the Java Standard Tag Library (JSTL) for handling the common JSP development tasks. There are also many third-party tag libraries that provide additional functionality to web developers, including the Spring Form tag library and Skyway Builder tag library.

SOLUTION

Since Skyway Builder is used to develop standard Spring MVC applications, there aren't aren't any special considerations for using third-party tag libraries. A developer can leverage other tag libraries as they normally would.

HOW IT WORKS

The steps for using a third-party tag library are:

  1. Add the tab library jar file to the WEB-INF/lib folder of the Web project

  2. Add the JSP directive to the top of the JSP page that will use the library

  3. Add the JSP tags to the JSP page

In the following example JSON-taglib will be added to a Skyway project. Download the jar file (json-taglib-0.4.1.jar) and copy to WEB-INF/lib folder of the web project. If you copy the project outside of Eclipse, be sure to refresh the project in Eclipse.

Add the JSP directive for JSON-taglib to the top of the JSP page. You will need to add the JSP directive to all the pages where you want to use the tags from the tag library.

Example 2.23. JSP Directive for using Third-Party Tag Library

<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>    

Next you can use the JSP tags from within your JSP page.

Example 2.24. Using Third-Party Tags

<json:object>
  <json:array name="items" var="item" items="${MyModel.contacts}">
    <json:object>
      <json:property name="type" value="${item.type}"/>
      <json:property name="name" value="${item.name}"/>
      <json:property name="summary" value="${item.summary}"/>
    </json:object>
  </json:array>
</json:object>  

When the JSP page is rendered, the output of JSP tag(s) will be emitted into the page.

RELATED RECIPES

  1. Implementing an HTML Form in JSP using standard HTML elements

  2. Implementing an HTML Form in JSP using Spring Form Tag Library

  3. Implementing an HTML Form in JSP using Skyway Tag Library