You are on page 1of 9

2.

2 BIRT Tag Library: Building a Custom Parameter Page

The Web Viewer now contains a tag library that can be used to
customize the behavior of the Viewer. This tag library can be deployed
by either deploying the viewer as normal or by using the new BIRT
Web Deployment project wizard. In addition, if you desire to have BIRT
deployed in one context and include the tag library in a separate
context this can be done by copying the birt.tld file to your WEB-
INF\tlds directory and copying coreapi.jar, modelapi,jar,
viewerservlets.jar and com.ibm.icu_3.6.1v20070417.jar from the
Viewer libs directory to the new context/web-inf/lib directory. Add the
following reference to your web.xml.

<jsp-config>
<taglib>
<taglib-uri>/birt.tld
<taglib-location>/WEB-INF/tlds/birt.tld
</taglib>
</jsp-config>

The following tags are now available:

enlarge

The parameterPage tag can be used to construct your own parameter


page before calling the BIRT Viewer. In addition to calling the Viewer
several attributes are provided to customize the Viewer appearance
and functionality.

For example the following JSP code will present the user with a set of
text boxes to enter the two parameters required for the report. The
pattern attribute specifies the Servlet mapping to be used and can be
set to frameset, run or preview.
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/birt.tld" prefix="birt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
</head>
<body>

<birt:parameterPage id="birtParmPage"
reportDesign="TopNPercent.rptdesign"
name="my form"
pattern="frameset"
height="600"
width="800"
format="html"
title="My Viewer Tag"
isCustom="true"
showTitle="true"
showToolBar="true"
showNavigationBar="true"
>
TOP COUNT PARAMETER
<input type="Text" name="Top Count">
<br><br>
TOP PERCENT PARAMETER
<input type="Text" name="Top Percentage">
<br><br>
<input type="Submit" value="Run Report">
</birt:parameterPage>
</body>
</html>

If you wish the BIRT Engine to return the HTML it generates for the
parameter you can use the paramDef tag in conjunction with the
parameterPage tag.

The following code will call the BIRT engine to populate each level of a
cascade.
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/birt.tld" prefix="birt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
</head>
<style type="text/css">
.class1 { background-color:#ff0000; color: #ffffff; }
</style>
<body>

Parameter Page 1
<br>
<birt:parameterPage
id="report1"
name="page1"
reportDesign="cascade_report.rptdesign"
isCustom="true"
pattern="frameset">

Cascading Parameter1: <birt:paramDef id="5" name="Country" />


<br><br>
Cascading Parameter2: <birt:paramDef id="6" name="City"/>
<br><br>
Cascading Parameter3: <birt:paramDef id="7" name="Customer"
cssClass="class1"/>
<br><br>
<input type="submit" name="submit" value="Sumbit form"/>
<br><br>
</birt:parameterPage>
<br>
</body>
</html>

This code will produce the following output. Notice that the third level
is also being customized by using a style.
enlarge

Download the 2.2 build and try out the new tag library.

Posted by Jason Weathersby at 4:28 PM

17 comments:

Anonymous said...

Does the taglib support JavaServer Faces applications? A few


sentences about integration with JSF would be nice.

TIA,
Nils Kassube

9:11 AM
Jason Weathersby said...

Nils,

I did some testing with JSF 1.1 using Tomcat 5.5 and did not
have much luck. Most of the tags wrap the results in an IFrame
and use AJAX. Ideally I would have thought the %lt;f:verbatim>
tag would have worked, but not on my installation. The following
tag works because the results are returned in a div without
AJAX.

%lt;%@ page language="java" contentType="text/html;


charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
%lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
%lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
%lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
%lt;%@ taglib uri="/birt.tld" prefix="birt" %>

%lt;html>

%lt;f:view>
%lt;body>

%lt;birt:report id="birtViewer"
reportDesign="TopNPercent.rptdesign"
height="600"
width="800"
format="html"
isHostPage="false"
reportContainer="div"
>
%lt;birt:param name="Top Count" value="3">%lt;/birt:param>
%lt;/birt:report>

%lt;/body>

%lt;/f:view>

%lt;/html>

2:02 PM
Anonymous said...

So do I tried to use the BIRT tag with jsf and I found the same
problems of yours. I use the 'reportContainer="div"' and this do,
but If I use the ajax results the thing not work. Have some news
about?

Stefano

1:04 PM
Jason Weathersby said...

Stefano

I do not have an update on this yet. Can you log a bugzilla entry
for your issue?
Jason

6:45 AM
Anonymous said...

Hi Jason,
happy to read that you answered me, I use in my web app the
birt tag, althought I don't know use it very well. Unfortunately
the documentations that I found are few, and sometime not very
clear... So first of all I ask you if you have some link where I
found it more...
However, if you thought that the problem is inside of the tag, I
can replicate the problem with a little code and put in the
bugzilla.
Thanks

3:26 PM
Jason Weathersby said...

Can you please log a bug for it.


Here is the updated Viewer page that discusses the tags:
http://www.eclipse.org/birt/phoenix/deploy/viewerUsage2.2.php

7:15 AM
Jason Weathersby said...

/deploy/viewerUsage2.2.php

7:16 AM
Anonymous said...

Is it possible for you to create a full example of a report with


custom parameters form and the deployment steps needed?

I read your post but I still don't know how to do it..

Thanks.

4:51 AM
Jason Weathersby said...

Take a look at the AIUC 2007 presentation Deploying the BIRT


Engine located here:
http://www.eclipse.org/birt/phoenix/presos/

The source code link has a directory in it called BirtWTP. In that


directory there is a webcontent directory which contains a jsp
page named BirtParmCustom.jsp which is an example of using
the custom parameter page. If you deploy the normal viewer
and add this page to the BIRT example viewer, it should work.

Jason

7:33 AM
Anonymous said...

I tried and copied these two files to the viewer dir:


1. TopNPercent.rptdesign
2. BirtParmCustom.jsp
The report works fine, but I haven't seen the custom parameters
page. I still don't understand how to connect a report to a
parameter page. Can you tell me how it is done?

Thanks again!

1:39 AM
Jason Weathersby said...

What happens when you display


BirtParmCustom.jsp?

The reportDesign attribute ties it to a specific report.


reportDesign="TopNPercent.rptdesign"

6:40 AM
Anonymous said...

it works fine and the report runs but when I press on the "Run
Report" button of the viewer I see again the default parameters
page

I want to link somehow the report to the custom parameters


page when I use the viewer frameset

8:21 AM
Jason Weathersby said...
I see. You will need to make a JavaScript modification.

Under the
webcontent/birt/ajax/ui/report directory open up the
AbstractBaseReportDocument.js file and look for the
__beh_parameter function.

This function is called when you select the parameter button in


the viewer. You could change the function to something like:
__beh_parameter : function( id )
{
//birtParameterDialog.__cb_bind( );
window.location=
"http://localhost:8080/BIRTWTP/BirtParmCustom.jsp"
}

This may not be ideal as this will affect all reports. Another
option is to turn off the toolbar in using the taglib attribute
showToolBar="false" and implement your own. Or use the code
above and do a check on the report you are currently viewing.

Jason

8:56 AM
Anonymous said...

When I press the button the custom parameters form is shown -


but when I first run the report I see the default form.
Is there a way to fix it?

9:21 AM
Jason Weathersby said...

How are you first running the report? Are you not running it
through the custom parameter jsp page first?

11:05 AM
Anonymous said...

no I use birt frameset and the parameters page automatically


shown in a pop-up window

12:59 AM
Jason Weathersby said...
You could modify the
BirtParameterDialog.js file.
Change the __bind function to redirect.

__bind : function( data )


{
window.location =
"http://localhost:8080/BIRTWTP/BirtParmCustom.jsp"

You might also like