我想使用java.struts2对JasperReports的master_report和subreport接受两个或更多参数。

这是我的代码段:

JasperAction.java:

private String Para_rin;
private String[] Para_rin_sub1;

public String CreateRep_rin() throws Exception {
     try {
            param_rin = new HashMap<String, Object>();
            param_rin.put("Para_rin", new Integer(Para_rin)); //  Masterreport's parameter
            param_rin.put("Para_rin_sub1", Para_rin_sub1); //  SubReport's parameter
            System.out.println("param_rin"+param_rin);
         } catch (Exception e) {
                    e.printStackTrace();
                    return ERROR;
         }
     return "jasper-rin";
}


master.jrxml:

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["G:\\pages\\iReport\\"]]></defaultValueExpression>
</parameter>
<parameter name="Para_rin_sub1" class="java.util.List"/>
<parameter name="Para_rin" class="java.lang.Integer"/>
<queryString>
    <![CDATA[select * from iv_raw_in where ID=$P{Para_rin}]]>
</queryString>


subreport.jrxml:

<parameter name="Para_rin_sub1" class="java.util.List">
    <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="Para_rin" class="java.lang.Integer" isForPrompting="false"/>
<queryString>
    <![CDATA[select * from iv_raw_in where $X{IN,ID,Para_rin_sub1}]]>
</queryString>


jsp:



<s:form id="jasper" action="jasper_CreateRep_rin" namespace="/pages/iReport">
  <TABLE id="reptbl" width="350px" border="1">
    <TR>
      <td>
        MasterParam :<s:textfield name="Para_rin" label="Stock" />SubParam :<s:textfield name="Para_rin_sub1" label="sub-Parameters" />

        <s:submit value="Generate Stock Report" type="button" />
      </td>
      <td>
        <s:radio label="format" name="rptFmt" list="#{'html':'HTML','pdf':'PDF'}" value="pdf" />
      </td>
    </TR>
  </TABLE>
</s:form>


现在我遇到了一些错误,例如:

Database Connected
reportName: rep_rin
Format pdf  -- rptFmt  Exception::net.sf.jasperreports.engine.fill.JRExpressionEvalException:       Error evaluating expression :
Source text : $P{Para_rin_sub1}.toArray()


我该如何完成?

最佳答案

您需要在master.jrxml中添加subreportParameter。查看样本

<subreport>
    <subreportParameter  name="Para_rin_sub1">
        <subreportParameterExpression><![CDATA[$P{Para_rin_sub1}]]></subreportParameterExpression>
    </subreportParameter>
</subreport>

10-08 00:07