---
title: "birt应用"
author: "iamlibo"
date: "2008-05-16T16:14:00Z"
tags: []
slug: "birt"
draft: false
lastmod: "2008-05-16T16:14:00Z"
id: 274385
url: "https://iamlibo.iteye.com/blog/274385"
---

有转载有原创,就算做个整理吧.

1、row 的背景颜色交替变换

选中table -&gt;details 然后在

onPrepare方法中加入下面代码

var count=1;

在onCreate方法中加入下面代码

count++;  
this.getStyle().backgroundColor=(count%2==0?"red":"blue");

这样表格就可以是红蓝交替显示了。

2、按一定的条件显示特定行,比如以红色显示数量小于0的行

if( row\["inQ"]&lt;0)  
this.getStyle().backgroundColor="red";

其中之一"inQ"是表中的列名,不一定是数据集成的列名，一开始以为是数据集成的列名，搞了好长时间。如果列名与数据集中的列名一样就没有问题了。

3、参数类型

birt 报表中的日期(date)型参数是java.sql.Date而不是java.util.Date

是看birt 源码才知道，下面是检查参数类型的方法的代码

private boolean validateParameterValueType(String paramName, Object paramValue, String type, ScalarParameterHandle paramHandle)  
throws ParameterValidationException  
{  
if("decimal".equals(type) || "float".equals(type))  
if(paramValue instanceof Number)  
return true;  
else  
throw new ParameterValidationException("Error.InvalidParameterType", new String\[] {  
paramName, type, paramValue.getClass().getName()  
});  
if("dateTime".equals(type))  
if(paramValue instanceof Date)  
return true;  
else  
throw new ParameterValidationException("Error.InvalidParameterType", new String\[] {  
paramName, type, paramValue.getClass().getName()  
});  
if("date".equals(type))  
if(paramValue instanceof java.sql.Date)  
return true;  
else  
throw new ParameterValidationException("Error.InvalidParameterType", new String\[] {  
paramName, type, paramValue.getClass().getName()  
});  
if("time".equals(type))  
if(paramValue instanceof Time)  
return true;  
else  
throw new ParameterValidationException("Error.InvalidParameterType", new String\[] {  
paramName, type, paramValue.getClass().getName()  
});  
if("string".equals(type))  
{  
if(paramHandle.isRequired())  
{  
String value = paramValue.toString().trim();  
if(value.length() == 0)  
throw new ParameterValidationException("Error.ParameterValueBlank", new String\[] {  
paramName  
});  
}  
return true;  
}  
if("boolean".equals(type))  
{  
if(paramValue instanceof Boolean)  
return true;  
else  
throw new ParameterValidationException("Error.InvalidParameterType", new String\[] {  
paramName, type, paramValue.getClass().getName()  
});  
} else  
{  
return true;  
}  
}

Technorati : [birt](http://technorati.com/tag/birt)