我正在尝试创建具有三行n列的crossTab。我使用了CrosstabDataset和JRBeanCollectionDataSource来显示我的数据。我的问题是我只能显示CollectionDataSource中的最后一个对象,而我无法访问crossDataSet中的数据。
注意:
我使用JRDesignCrosstab(Java代码)来创建crossTab。
public static JRDesignCrosstab CrosstabPanel(String parameterName , JasperDesign jasperDesign, JRDesignDataset subDataset) throws JRException {
// parameter
JRDesignParameter parameter = new JRDesignParameter();
parameter.setName(parameterName);
parameter.setValueClass(java.lang.Object.class);
jasperDesign.addParameter(parameter);
subDataset.addParameter(parameter);
//Gross Tab
JRDesignCrosstab crosstab = new JRDesignCrosstab();
crosstab.setX(-90);
crosstab.setY(-4);
crosstab.setWidth(600);
crosstab.setHeight(400);
//Expression :
JRDesignExpression expression = new JRDesignExpression("$P{"+parameterName+"}");
//CrosstabDataset
JRDesignCrosstabDataset dataSet = new JRDesignCrosstabDataset();
//datasetrun
JRDesignDatasetRun dsr = new JRDesignDatasetRun();
dsr.setDatasetName(subDataset.getName());
dsr.setDataSourceExpression(expression);
//datasetrun into CrosstabDataset
dataSet.setResetType(ResetTypeEnum.NONE);
dataSet.setDatasetRun(dsr);
crosstab.setDataset(dataSet);
//Bucket Row
JRDesignCrosstabBucket bucket = new JRDesignCrosstabBucket();
JRDesignExpression expressionField = new JRDesignExpression();
expressionField.setText("$F{commissionSimPaye}");
bucket.setValueClassName("net.sf.jasperreports.engine.DataSource");
bucket.setExpression(expressionField);
//Row Group;
JRDesignCrosstabRowGroup rowGroup = new JRDesignCrosstabRowGroup();
rowGroup.setName("rowGroup");
rowGroup.setBucket(bucket);
rowGroup.setWidth(68*2+1);
rowGroup.setTotalPosition(CrosstabTotalPositionEnum.END);
crosstab.addRowGroup(rowGroup);
//Bucket Second Row
bucket = new JRDesignCrosstabBucket();
expressionField = new JRDesignExpression();
expressionField.setText("$F{commissionSimPaye}");
bucket.setValueClassName("net.sf.jasperreports.engine.ReportContext");
bucket.setExpression(expressionField);
//Row Group;
rowGroup = new JRDesignCrosstabRowGroup();
rowGroup.setName("secondRowGroup");
rowGroup.setBucket(bucket);
rowGroup.setWidth(68*2+1);
rowGroup.setTotalPosition(CrosstabTotalPositionEnum.END);
crosstab.addRowGroup(rowGroup);
//Bucket Column
bucket = new JRDesignCrosstabBucket();
expressionField = new JRDesignExpression();
expressionField.setText("$F{commissionSimCalcule}");
bucket.setValueClassName("java.lang.Object");
bucket.setExpression(expressionField);
//ColumnGroup
JRDesignCrosstabColumnGroup ColumnGroup = new JRDesignCrosstabColumnGroup();
ColumnGroup.setName("columnGroup");
ColumnGroup.setBucket(bucket);
ColumnGroup.setHeight(60);
ColumnGroup.setTotalPosition(CrosstabTotalPositionEnum.END);
crosstab.addColumnGroup(ColumnGroup);
JRDesignExpression expressionMesaure = new JRDesignExpression();
expressionMesaure.setText("$F{commissionSimCalcule}");
JRDesignCrosstabMeasure measure = new JRDesignCrosstabMeasure();
measure.setName("ColumContent"+0);
measure.setValueExpression(expressionMesaure);
measure.setValueClassName("java.lang.Object");
crosstab.addMeasure(measure);
expressionMesaure = new JRDesignExpression();
expressionMesaure.setText("$F{commissionSimPaye}");
measure = new JRDesignCrosstabMeasure();
measure.setName("ColumContent"+1);
measure.setValueExpression(expressionMesaure);
measure.setValueClassName("java.lang.Object");
crosstab.addMeasure(measure);
expressionMesaure = new JRDesignExpression();
expressionMesaure.setText("$F{commissionSimAPaye}");
measure = new JRDesignCrosstabMeasure();
measure.setName("ColumContent"+2);
measure.setValueExpression(expressionMesaure);
measure.setValueClassName("java.lang.Object");
crosstab.addMeasure(measure);
//contenu de la cellule
JRDesignTextField textField = new JRDesignTextField();
JRDesignCrosstabCell cell = new JRDesignCrosstabCell();
JRDesignExpression expressionTextField = new JRDesignExpression();
JRDesignCellContents cellContents = new JRDesignCellContents();
textField.setX(0);
textField.setY(0);
textField.setWidth(68);
textField.setHeight(20);
textField.setHorizontalAlignment(HorizontalAlignEnum.RIGHT);
textField.getLineBox().getLeftPen().setLineWidth(1);
textField.getLineBox().getTopPen().setLineWidth(1);
textField.getLineBox().getRightPen().setLineWidth(1);
textField.getLineBox().getBottomPen().setLineWidth(1);
cell.setHeight(20);
cell.setWidth(68);
expressionTextField.setText("$V{ColumContent"+0+"}");
textField.setExpression(expressionTextField);
cellContents.addElement(textField);
cell.setContents(cellContents);
crosstab.addCell(cell);
return crosstab;
}
最佳答案
问题解决了,我研究了JRBeanCollectionDataSource的结构