I did not find a simple method to solve this problem using DynamicJasper API.
But this can be solved with help DJ.
This is the source code of the main class for building the report.
public class BasicReportTest {
private JasperPrint m_jasperPrint;
private JasperReport m_jasperReport;
private Map m_params = new HashMap();
private DynamicReport m_dynamicReport;
public DynamicReport buildReport() throws Exception {
Style detailStyle = new Style();
detailStyle.setBorder(Border.THIN);
detailStyle.setBlankWhenNull(true);
Style headerStyle = new Style();
headerStyle.setFont(Font.COURIER_NEW_BIG_BOLD);
headerStyle.setBorder(Border.THIN);
headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
headerStyle.setFont(Font.ARIAL_BIG);
FastReportBuilder drb = new FastReportBuilder();
drb.addColumn("State", "state", String.class.getName(), 30, detailStyle, headerStyle)
.addColumn("Branch", "branch", String.class.getName(), 30, detailStyle, headerStyle)
.addColumn("Item", "item", String.class.getName(), 50, detailStyle, headerStyle)
.addColumn("Amount", "amount", Float.class.getName(), 60, detailStyle, headerStyle)
.setTitle("The report with empty rows")
.setUseFullPageWidth(true);
DynamicReport dr = drb.build();
return dr;
}
public void testReport() throws Exception {
m_dynamicReport = buildReport();
JRDataSource dataSource = getDataSource();
m_jasperReport = DynamicJasperHelper.generateJasperReport(m_dynamicReport,
getLayoutManager(), m_params);
m_jasperPrint = JasperFillManager.fillReport(m_jasperReport, m_params, dataSource);
exportReport();
}
protected LayoutManager getLayoutManager() {
return new CustomLayoutManager();
}
public static void main(String[] args) throws Exception {
BasicReportTest test = new BasicReportTest();
test.testReport();
}
}
This line of code detailStyle.setBlankWhenNull(true);gives us the opportunity to show the value as empty in . It is like using an expression nulltextField
<textField isBlankWhenNull="true">
jrxml.
"" xml- :
<textField isBlankWhenNull="true">
<reportElement ... isRemoveLineWhenBlank="true"/>
, DJ () JRElement.setRemoveLineWhenBlank(boolean isRemoveLineWhenBlank).
LayoutManager - CustomLayoutManager.
:
public class CustomLayoutManager extends ClassicLayoutManager {
@Override
protected void transformDetailBandTextField(AbstractColumn column, JRDesignTextField textField) {
super.transformDetailBandTextField(column, textField);
if (column.getStyle().isBlankWhenNull()) {
textField.setRemoveLineWhenBlank(true);
}
}
}
transformDetailBandTextField, DJ Detail.