Skip to content

Commit

Permalink
gh-153: fix rendering of last column footer in table component
Browse files Browse the repository at this point in the history
  • Loading branch information
teodord committed May 11, 2021
1 parent a22dee0 commit 337f5ed
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,25 @@
package net.sf.jasperreports.components.table.fill;

import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
import net.sf.jasperreports.engine.fill.JRVerticalFiller;

/**
* This scriptlet implementation for table component ended up not being used as a scriptlet,
* because its prior technique to detect the presence of at least one detail band on the page
* was not accurate in case the detail was overflowing onto the new page.
*
* Its current technique uses a flag in the report filler to detect the presence of a detail band
* and thus this scriptlet implementation itself is only used as a vehicle to add a built-in parameter
* to the table component subreport, to give access to the filler and its internal the flag.
*
* @author Lucian Chirita (lucianc@users.sourceforge.net)
*/
public class TableReportScriptlet extends JRDefaultScriptlet
{

private boolean detailOnPage;

@Override
public void afterDetailEval() throws JRScriptletException
{
detailOnPage = true;
}

@Override
public void afterPageInit() throws JRScriptletException
{
detailOnPage = false;
}

public boolean hasDetailOnPage()
{
return detailOnPage;
return ((JRVerticalFiller)dataset.getFiller()).hasDetailOnPage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.Map;

import net.sf.jasperreports.engine.fill.JRFillDataset;
import net.sf.jasperreports.engine.fill.JRFillField;
import net.sf.jasperreports.engine.fill.JRFillGroup;
import net.sf.jasperreports.engine.fill.JRFillParameter;
Expand All @@ -47,6 +48,7 @@ public abstract class JRAbstractScriptlet
/**
*
*/
protected JRFillDataset dataset;
protected Map<String,JRFillParameter> parametersMap;
protected Map<String,JRFillField> fieldsMap;
protected Map<String,JRFillVariable> variablesMap;
Expand All @@ -64,6 +66,22 @@ public JRAbstractScriptlet()
/**
*
*/
public void setData(JRFillDataset dataset)
{
this.dataset = dataset;

setData( // keep this deprecated method call here just in case it was overridden in scriptlet implementations
dataset.getParametersMap(),
dataset.getFieldsMap(),
dataset.getVariablesMap(),
(JRFillGroup[])dataset.getGroups()
);
}


/**
* @deprecated Replaced by {@link #setData(JRFillDataset)}.
*/
public void setData(
Map<String,JRFillParameter> parsm,
Map<String,JRFillField> fldsm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public class JRFillDataset implements JRDataset, DatasetFillContext
/**
*
*/
protected JRAbstractScriptlet delegateScriptlet = new JRFillDatasetScriptlet(this);
protected JRAbstractScriptlet delegateScriptlet = new JRFillDatasetScriptlet();

/**
* The value of the {@link JRParameter#REPORT_MAX_COUNT max count} parameter.
Expand Down Expand Up @@ -310,6 +310,12 @@ public JRFillDataset(BaseReportFiller filler, JRDataset dataset, JRFillObjectFac
? new ArrayList<DatasetPropertyExpression>(0)
: new ArrayList<DatasetPropertyExpression>(Arrays.asList(datasetPropertyExpressions));
}


public BaseReportFiller getFiller()
{
return filler;
}


private void setParameters(JRDataset dataset, JRFillObjectFactory factory)
Expand Down Expand Up @@ -649,7 +655,7 @@ public void setParameterValues(Map<String,Object> parameterValues) throws JRExce
}

scriptlets = createScriptlets(parameterValues);
delegateScriptlet.setData(parametersMap, fieldsMap, variablesMap, groups);//FIXMESCRIPTLET use some context
delegateScriptlet.setData(this);//FIXMESCRIPTLET use some context

// initializing cache because we need the cached parameter values
cacheInit();
Expand Down Expand Up @@ -1897,6 +1903,11 @@ public JRField[] getFields()
return fields;
}

public Map<String,JRFillField> getFieldsMap()
{
return fieldsMap;
}

@Override
public JRSortField[] getSortFields()
{
Expand All @@ -1909,6 +1920,11 @@ public JRVariable[] getVariables()
return variables;
}

public Map<String,JRFillVariable> getVariablesMap()
{
return variablesMap;
}

@Override
public JRGroup[] getGroups()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package net.sf.jasperreports.engine.fill;

import java.util.Iterator;
import java.util.Map;

import net.sf.jasperreports.engine.JRAbstractScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
Expand All @@ -35,33 +34,14 @@
public class JRFillDatasetScriptlet extends JRAbstractScriptlet
{

/**
*
*/
private JRFillDataset dataset;

/**
*
*/
public JRFillDatasetScriptlet(JRFillDataset dataset)
{
this.dataset = dataset;
}


@Override
public void setData(
Map<String,JRFillParameter> parsm,
Map<String,JRFillField> fldsm,
Map<String,JRFillVariable> varsm,
JRFillGroup[] grps
)
public void setData(JRFillDataset dataset)
{
super.setData(parsm, fldsm, varsm, grps);
super.setData(dataset);

for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();)
{
it.next().setData(parsm, fldsm, varsm, grps);
it.next().setData(dataset);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class JRVerticalFiller extends JRBaseFiller
{

private static final Log log = LogFactory.getLog(JRVerticalFiller.class);

protected boolean hasDetailOnPage;


/**
*
Expand Down Expand Up @@ -80,6 +83,12 @@ public JRVerticalFiller(

setPageHeight(pageHeight);
}


public boolean hasDetailOnPage()
{
return hasDetailOnPage;
}


@Override
Expand Down Expand Up @@ -435,6 +444,8 @@ private void fillPageHeader(byte evaluation) throws JRException

columnHeaderOffsetY = offsetY;

hasDetailOnPage = false;

isNewPage = true;
}

Expand Down Expand Up @@ -860,6 +871,8 @@ private void fillDetail() throws JRException
}
}
}

hasDetailOnPage = atLeastOneDetailBandPrinted;

isNewPage = false;
isNewColumn = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
92fbd22b670fdf91c06281696e1bf722964241c7
92838f75be06f6ed55a3880e7369dbb5a1bb8795

0 comments on commit 337f5ed

Please sign in to comment.