Using the Crystal Tag Libraries

Now that you understand how the report viewer works, its beneficial to understand some of the ways that it can be used in a more productive manner. Java tag libraries are a great way to accomplish this. A tag library (taglib) is an HTML-like tag that can be embedded inside a JSP page; it has some compiled code logic behind it that knows how to render itself to HTML. The beauty of a tag library is that you don need to clog up your JSP page with a bunch of code; you simply need to insert the tag. When Business Objects created the HTML report viewer, they were wise enough to create some Java tag libraries alongside it. This is not to say you could not create your own tag libraries to suit your own needs, but the ones provided with the product will probably meet most requirements.

Refer to the Application Server Configuration section in this chapter for steps to configure the Crystal tag libraries. After youve finished the setup, you can start adding the tags to your page. The first step in using the tag is to add the taglib directive to the top of your JSP page. This directive looks like this:

<%@ taglib uri="/crystal-tags-reportviewer.tld" prefix="crviewer" %>

This indicates to the JSP page that any time it finds a tag prefixed with crviewer, it should look in the crystal-tags-reportviewer.tlb file to find out how to work with that tag.

There are two tags that must be added to the JSP page: viewer and report. Listing 28.2 shows a simple page using the viewer and report tags.

Listing 28.2. Using the Tag Libraries

<%@ taglib uri="/crystal-tags-reportviewer.tld" prefix="crviewer" %>


The viewerName and reportSourceType attributes of the viewer tag are required. The viewerName can be set to blank unless there are multiple viewer tags on the same page, in which case youll need to name them uniquely. There is only one report source type supported in the Java Reporting Component, which is "reportingComponent." Inside the viewer tag, youll see a report tag. For the reportName attribute, pass in the name of the report you want to display. The output of this page would be exactly the same as the output of the previous code example using inline Java code. The advantage of this page is that it is cleaner and simpler. To customize the viewer, rather than writing code, simply add attributes to the viewer tag. For example, adding the following attribute to the viewer tag hides the group tree:


There are many other attributes supported. Consult the documentation for a full list but the general rule is that most methods on the CrystalReportViewer object have a corresponding tag library attribute.

Special Edition Using Crystal Reports 10
Special Edition Using Crystal Reports 10
ISBN: 0789731134
EAN: 2147483647
Year: 2003
Pages: 341
Simiral book on Amazon © 2008-2017.
If you may any questions please contact us: