Custom JRVerticalFiller not called for subreports, thus not rendering background colors

0

I am using jasperreports-6.0.3 in java to obtain a single report with multiple subreports. This all works rather well until I wish to add background table cell colors for one of my subreports.

In the datasource of this subreport table, there is a field that has the textual representation of a java AWT color, ie. the text is java.awt.Color=[r=61,g=54,b=124]. I want the cell to render it's background color based on this RGB color. For this I have created a custom class TableCellRendererFillTextField that extends JRFillTextField and sets the field's background to that particular color.

The TableCellRendererFillTextField  is created in my custom JRFillObjectFactory, that is initiliazed in my custom class TableCellRendererVerticalFiller that extends JRVerticalFiller.

 

protected class TableCellRendererVerticalFiller extends JRVerticalFiller
{
    ...
 
    @Override
    protected JRFillObjectFactory initFillFactory()
    {
      super.initFillFactory();
 
      return new TableCellRendererFillObjectFactory(this);
    }
 
    ...
}
 
 
protected class TableCellRendererFillObjectFactory extends JRFillObjectFactory
{
    ...
 
    @Override
    public void visitTextField(JRTextField pJRTextField)
    {
        JRFillTextField fillTextField = null;
 
        if (pJRTextField != null)
        {
            fillTextField = (JRFillTextField)get(pJRTextField);
            if (fillTextField == null)
            {
                fillTextField = new TableCellRendererFillTextField(filler, pJRTextField, this);
            }
        }
        setVisitResult(fillTextField);
    }
 
    ...
}
 
 
protected class TableCellRendererFillTextField extends JRFillTextField
{
    ...
 
    @Override
    public JRPrintElement fill() throws JRException
    {
        // here we set the background color of the element to the text value
        JRTemplatePrintText text = new TableCellRendererTemplatePrintText(row, column, getJRTemplateText(), printElementOriginator);
        return text;
    }
 
    ...
}

The following code generates my JasperPrint:

JasperReport jasperReport = DynamicJasperHelper.generateJasperReport(pDynamicReport, createLayoutManager(), pParameters); 
JRBaseFiller filler = new TableCellRendererVerticalFiller(reportContext, jasperReport); 
JasperPrint jasperPrint = filler.fill(pParameters, pJRDataSource); 
if (jasperPrint == null) return null;

This all works flawless when I do not add the tables as subreport, but set it to the main report. As soon as I use subreports, the class TableCellRendererVerticalFiller is not called. I believe this is due to the following method:

net.sf.jasperreports.engine.fill.JRFillSubreport#initSubreportFiller
 
...
 
switch (jasperReport.getPrintOrderValue())
{
 case HORIZONTAL :
 {
  subreportFiller = new JRHorizontalFiller(filler.getJasperReportsContext(), jasperReport, subFillerParent);
  break;
 }
 case VERTICAL :
 default :
 {
  subreportFiller = new JRVerticalFiller(filler.getJasperReportsContext(), jasperReport, subFillerParent);
  break;
 }
}
 
runner = getRunnerFactory().createSubreportRunner(this, subreportFiller);

Only a JRHorizontalFiller or JRVerticalFiller is used for the subreports.

My question is, how can I make it possible that my subreports use my custom TableCellRendererVerticalFiller class to render the background color of its text elements containing java.awt.Color[r=...,g=...,b=...]?

glennb's picture
2
Joined: Apr 29 2020 - 12:37am
Last seen: 6 months 3 days ago

0 Answers:

No answers yet
Feedback