JSP Tag Library Usage

Introduction

Davisor Chart's JSP tag library provides an easy way to add charts to JSP pages. The main benefit of chart tag library is that it dramatically reduces the amounts of chart related Java code necessary in JSP pages. In fact, in many cases, JSP tags are all that is needed.

JSP tags work by moving the definitions for the functionality provided by the tags from the JSP pages themselves into tag implementation classes. In doing so, Davisor Chart tag library makes JSP page authoring much more easier than plain JSP programming would be.

Davisor was the first vendor in the world to apply JSP tag libraries to conveniently generate chart images in JSP pages. Davisor's long experience in this field guarantees you the easiest and best performing Chart tags anywhere; the following chapters describe how you may use them to instantly elevate the visual appearance of your JSP web applications.

Usage

Actions that are delivered as tag libraries are imported into a JSP page using the taglib directive. They are available for use in the page using the prefix given by the directive.

<%@ taglib uri="davisorchart" prefix="chart" %>

The next step is to define some Chart XML that will determine the chart details. Chart XML is defined inside a Davisor JSP tag library <def> tag.

<chart:def>
  <chart> ... </chart>
</chart:def>

Alternatively, a source attribute can be used to set the source URL of Chart XML. In this case the <def> tag body content, if any, is ignored.

<chart:def source="URLtoChartXML">
  (content ignored)
</chart:def>

After chart data and attributes have been defined with a <def> tag, <out> tag is used to place the resulting chart at the JSP page.

... any JSP content ...
<chart:out/>
... more JSP content ...

There is also a shorthand notation for a def-out tag pair: out tag can use directly an external Chart XML document. This can be achieved by using out tag's source attribute. If source is used the def attribute is ignored.

... any JSP content ...
<chart:out source="URLtoChartXML"/>
... more JSP content ...

JSP page can contain several out tags that use the same or different chart definition. In this situation out tag can be used to override some of the chart attributes. Most frequently overridden is the "chartType" attribute. Chart tag library reference describes all chart tags and attributes.

<chart:out chartType="table"/>

If the JSP page contains several <def> tags the def attribute at <out> tag can be used to select wanted chart definition. Chart definition can contain several <attributes> Chart XML tags. Wanted <attributes> block is selected with attributes attribute.

<chart:out def="defID" attributes="attributesIDinsideDef"/>

Example

A JSP file using one <chart:def> and two <chart:out> tags.

Setup

  1. Copy "davisorchart.jar" file to "/WEB-INF/lib" subdirectory of your web application.
  2. Change your web application deployment descriptor "/WEB-INF/web.xml" file to include the following lines:
      <servlet>
        <servlet-name>getChart</servlet-name>
        <servlet-class>com.davisor.webapp.chart.ChartContentServlet</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>getChart</servlet-name>
        <url-pattern>/getChart</url-pattern>
      </servlet-mapping>
    
      <-- Optional mapping from davisorchart.jar to taglib URI (davisorchart). -->
      <taglib>
       <taglib-uri>davisorchart</taglib-uri>
       <taglib-location>/WEB-INF/lib/davisorchart.jar</taglib-location>
      </taglib>
    
      <-- Alternative way for servers that can not read the tld from the jar.
      <taglib>
       <taglib-uri>davisorchart</taglib-uri>
       <taglib-location>/WEB-INF/davisorchart.tld</taglib-location>
      </taglib>
      -->
    
  3. At the top of each JSP page in your application that needs to use the Davisor Chart tag library, add a taglib directive. The uri attribute must match the value you specified in the <taglib-uri> element in the web.xml or it can be a uri value (http://www.davisor.com/chart) defined in the tld . The chart prefix is used to identify tags from the Davisor Chart library within the current page.
    <%@ taglib uri="davisorchart" prefix="chart" %>
     or
    <%@ taglib uri="http://www.davisor.com/chart" prefix="chart" %>
    

For more information about the technical details of what actually happens in system level in each stage described here, please see the Under the Hood documentation.