包含动态列的表

时间:2016-08-23 06:37:20

标签: java jasper-reports

我用Google搜索,但我无法找到解决问题的方法

我在这种情况下:我的客户可以通过指定字段和数据字段来创建自己的表单 然后,向用户显示创建的表单,用户可以填写所需的数据

所有数据都存储在存储库中(mong DB) 然后我的Web应用程序的另一部分我的客户可以在表中查看所有已保存的数据

到目前为止一切都那么好......一切都很好

现在我需要在Excel或PDF文件中导出表单的所有数据

我正在使用Jasper Report来创建报告

问题是我不知道如何在报告中设计表格,因为我不知道列名和计数

实际上我将这个bean作为我的mongo db“record”的表示

FormDataModel

@Document(collection = "e_form_data")
public class FormDataModel extends AbstractModel {
    private static final long serialVersionUID = -1733975205300782871L;
    private String dataInserimento;
    @Field
    @Indexed(name = "e_form_id_idx")
    private String eFormId;
    @Field
    private Map<String, Object> eFormData;
    //Getter, setter and contructors.. omitted for smaller text
}

AbstractModel是:

AbstractModel

public abstract class AbstractModel implements Serializable {
    private static final long serialVersionUID = -3154415503243809601L;
    @Id
    protected String id;
    @Field
    protected String creatoDa;
    @Field
    protected String modificatoDa;
    @Field
    protected Date dataCreazione;
    @Field
    protected Date dataModifica;
    //Getter, setter and contructors.. omitted for smaller text
}

在我的FormDataModel中,属性 eFormData 表示填充由其他用户创建的Web表单的用户创建的dinamyc数据

这基本上意味着我不知道如何创建这个表单以及它将包含哪些字段

我刚才,Map键是我表的列,而Map值是列值 如何在报告中迭代/使用此地图?有什么建议吗?

修改

正如Petter Friberg所建议的那样,我会更加精确 问题是以下问题;假设我使用JRBeanCollectionDataSource作为数据源,假设我使用此代码来填充和创建我的报告:

List<FormDataModel> datiForm = //recover data from mongo repository
reportData.setDatiForm(datiForm);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("nomeForm", reportData.getFormName());
parameters.put("codiceForm", reportData.getFormCode());
parameters.put("descrizioneForm", reportData.getFormDescription());
InputStream fis = //Get input stream for company logo
parameters.put("logo", fis);
InputStream ris = //Get the input stream of the compiled report (I don't want to recompile report at every HTTP request)
InputStream compiledReport = ris;
JasperPrint jasperPrint = JasperFillManager.fillReport(compiledReport, parameters, new  JRBeanCollectionDataSource(datiForm, true));        JasperExportManager.exportReportToPdfFile(jasperPrint,"/home/angelo/Scrivania/report/report1.pdf");

因为yuo可以看到我从mongo存储库获取数据和其他一些信息,我使用JRBeanCollectionDataSource作为报表数据源 现在,我的Bean列表是使用 FormDataModel 对象构建的;我想在我的报告中构建的是一个表,其中列名是Map eFormData的键,列值是此映射的值 主要的问题是我不知道Map中包含什么,因为它是由另一个用户决定的,所以我正在寻找的是通过循环Map来在我的报告中构建表的方法;报告中的表格应如下所示:

<table>
  <!-- This first row is built by taking the keys in the Map of one element of my datasource -->
  <tr>
    <th>Map Key 1</th>
    <th>Map Key 2</th>
    <th>Map Key 3</th>
  </tr>
  <!-- Form here, each row is built by cycling my datasource and for each element i'll take the Map values to build the several columns of the row -->
  <tr>
    <td>Map Value 1</td>
    <td>Map Value 2</td>
    <td>Map Value 3</td>
  </tr>  
 </table>

现在我想我的jrxml中没有标准名称(例如col1,col2等...)因为如果我不知道表格中有多少列我应该使用未定义的名称col1, col2 ..... col10000希望在地图中不会出现超过10000个字段(非常常见的场景,但是当人们可以自由地做任何他们想做的事情时......可以做到) 什么是我的方案的最佳解决方案?我当时想要使用一个scriptlet,但我不确定如何使用它

我希望我能更明确地指出我被困的地方

而且:什么是动态碧玉?从未听说过他们

0 个答案:

没有答案
相关问题