无法在动态报告中显示pdf数据

时间:2016-07-18 05:45:57

标签: java pdf-generation ofbiz dynamic-reports

这里我使用了一个委托来从数据库中获取数据,而我正在使用ofbiz框架。

生成pdf的源代码:

public static String createTransactionSummaryReport(HttpServletRequest request, HttpServletResponse response) throws Exception{

    Delegator delegator = (Delegator)request.getAttribute("delegator");
    String accountName = request.getParameter("accountName");

    JasperReportBuilder report = report();

    response.setContentType("application/pdf");
    //OutputStream out = response.getOutputStream();

    report.columns(
           Columns.column("AccountName", "accountName", DataTypes.stringType()),
           Columns.column("Amount", "amount", DataTypes.bigDecimalType()),
           Columns.column("DebitAmount", "debitAmount", DataTypes.bigDecimalType()),
           Columns.column("CreditAmount", "creditAmount", DataTypes.bigDecimalType())
    ).title(Components.text("Transaction Summary Details"))
    .pageFooter(Components.pageXofY())
    .setDataSource(getCollectionData(delegator, accountName))
    .show();
    /*try {
        report.show();
        //report.toPdf(out);
    } catch(DRException ex) {
        ex.getCause().printStackTrace();
    }*/
    return "success";
}

private static JRDataSource getCollectionData(Delegator delegator, String accountName) {

    List<TransactionSummaryDataProvider> dataList = new ArrayList<TransactionSummaryDataProvider>();

    List<GenericValue> accTgTransaDetails = null;

    try {
        accTgTransaDetails =  delegator.findByAnd("AcctgTransEntrySums", UtilMisc.toMap("accountName",accountName));
    } catch(Exception ex) {
        ex.printStackTrace();
    }

    for(GenericValue eachData : accTgTransaDetails) {

        String accName = eachData.getString("accountName");
        BigDecimal amount = eachData.getBigDecimal("amount");
        BigDecimal debitAmount = eachData.getBigDecimal("debitAmount");
        BigDecimal creditAmount = eachData.getBigDecimal("creditAmount");

        dataList.add(new TransactionSummaryDataProvider(accName, amount, debitAmount, creditAmount));
    }

    return new JRBeanCollectionDataSource(dataList);
}

Bean类:

public class TransactionSummaryDataProvider {

    private String accountName;
    private BigDecimal amount;
    private BigDecimal debitAmount;
    private BigDecimal creditAmount;

    public TransactionSummaryDataProvider(String accountName, BigDecimal amount, BigDecimal debitAmount, BigDecimal creditAmount) {
        this.accountName = accountName;
        this.amount = amount;
        this.debitAmount = debitAmount;
        this.creditAmount = creditAmount;
    }

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public BigDecimal getDebitAmount() {
        return debitAmount;
    }

    public void setDebitAmount(BigDecimal debitAmount) {
        this.debitAmount = debitAmount;
    }

    public BigDecimal getCreditAmount() {
        return creditAmount;
    }

    public void setCreditAmount(BigDecimal creditAmount) {
        this.creditAmount = creditAmount;
    }
}

.show()方法抛出InvocationTargetException

我该如何解决这个问题?

dataList中有必需的数据,但这些数据不会显示在pdf中。

1 个答案:

答案 0 :(得分:0)

为了更好的体验,请在Apache OFBiz项目的用户ml中询问此类问题,请参阅此处如何连接更多OFBiz专家:https://ofbiz.apache.org/mailing-lists.html