Jump to content
We've recently updated our Privacy Statement, available here ×

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


Recommended Posts

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;    }    ...}[/code]

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;[/code]

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);[/code]

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=...]?

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...