我是jasper报道的新手。我正在尝试使用List生成发票帐单。
我提到了this帖子以获得一些帮助,但我得到了这个JRException
我的碧玉填充代码
String [] prod = request.getParameterValues("prodn[]");
String [] pkgdate = request.getParameterValues("pkgdate[]");
String [] manufact = request.getParameterValues("manufact[]");
String [] exp = request.getParameterValues("exp[]");
String [] batch = request.getParameterValues("batch[]");
String [] unit = request.getParameterValues("unit[]");
String [] qty = request.getParameterValues("qty[]");
String [] subtot = request.getParameterValues("subtot[]");
Map<String, Object> param = new HashMap<String, Object>();
jasperPrint = JasperFillManager.fillReport(jasperReport, param, getDataSource(prod,pkgdate,manufact,exp,batch,unit,qty,subtot));
JasperViewer.viewReport(jasperPrint, false);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static JRDataSource getDataSource(String[] prod, String[] pkgdate,
String[] manufact, String[] exp, String[] batch, String[] unit,
String[] qty, String[] subtot) {
// TODO Auto-generated method stub
Collection<DataBean> coll = new ArrayList<DataBean>();
DataBean bean = null;
for(int i=0;i<prod.length;i++)
{
bean = new DataBean(Arrays.asList(prod[i]),Arrays.asList(pkgdate[i]),Arrays.asList(manufact[i]),Arrays.asList(exp[i]),Arrays.asList(batch[i]),Arrays.asList(unit[i]),Arrays.asList(qty[i]),Arrays.asList(subtot[i]));
coll.add(bean);
}
return new JRBeanCollectionDataSource(coll);
}
我的豆子
private List<String> p_names;
private List<String> p_pkg;
private List<String> p_manf;
private List<String> p_exp;
private List<String> p_batch;
private List<String> p_unit;
private List<String> p_qty;
private List<String> p_sub;
public DataBean(List<String> prodnamelist,List<String> pkgdatelist,List<String> manfdatelist,List<String> expdatelist,List<String> batchlist,List<String> unitlist,List<String> qtylist,List<String> subtotlist) {
// TODO Auto-generated constructor stub
p_names = prodnamelist;
p_pkg = pkgdatelist;
p_manf = manfdatelist;
p_exp = expdatelist;
p_batch = batchlist;
p_unit = unitlist;
p_qty = qtylist;
p_sub = subtotlist;
}
public List<String> getP_names() {
return p_names;
}
public List<String> getP_pkg() {
return p_pkg;
}
public List<String> getP_manf() {
return p_manf;
}
public List<String> getP_exp() {
return p_exp;
}
public List<String> getP_batch() {
return p_batch;
}
public List<String> getP_unit() {
return p_unit;
}
public List<String> getP_qty() {
return p_qty;
}
public List<String> getP_sub() {
return p_sub;
}
我的jrxml文件
由于jrxml文件非常长,我只发布了必需的文件
<subDataset name="tableDataset" uuid="f13e6d36-5148-4ecc-bbe3-3035def80980">
<queryString>
<![CDATA[]]>
</queryString>
<field name="prodname" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="pkgdate" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="manfdate" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="expdate" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="batch" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="unit" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="qty" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<field name="subtot" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<field name="pkgdatelist" class="java.util.Collection"/>
<field name="manfdatelist" class="java.util.Collection"/>
<field name="expdatelist" class="java.util.Collection"/>
<field name="batchlist" class="java.util.Collection"/>
<field name="unitlist" class="java.util.Collection"/>
<field name="qtylist" class="java.util.Collection"/>
<field name="subtotlist" class="java.util.Collection"/>
<field name="prodnamelist" class="java.util.Collection"/>
<componentElement>
<reportElement x="0" y="90" width="79" height="30" uuid="48bd4b3d-a43c-4e57-89ad-d1114b214e29"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="012ce25a-4b36-4400-97e2-a0ec1e27bb80">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{prodnamelist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="79">
<textField>
<reportElement x="0" y="0" width="79" height="30" uuid="8cf1ecb5-5fdf-4dc9-a970-244f4d31a1b9"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{prodname}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="79" y="90" width="71" height="30" uuid="48bd4b3d-a43c-4e57-89ad-d1114b214e29"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="012ce25a-4b36-4400-97e2-a0ec1e27bb80">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{pkgdatelist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="71">
<textField>
<reportElement x="0" y="0" width="71" height="30" uuid="5d91cd84-0beb-40e7-94bc-0ee2e846755f"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{pkgdate}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="150" y="90" width="70" height="30" uuid="c002cbfb-ca6e-4939-91c8-30a8dccbc650"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="c4885197-91d5-4e41-935f-fbbae897321f">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{manfdatelist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="70">
<textField>
<reportElement x="0" y="0" width="70" height="30" uuid="ff5f611b-f905-49f6-92bf-70ef1df02d5f"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{manfdate}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="220" y="90" width="70" height="30" uuid="991c37d9-4c9c-4340-ab5f-810903caa8b6"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="2b5275d1-ae2f-4cfd-8c32-79f64c304af9">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{expdatelist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="70">
<textField>
<reportElement x="0" y="0" width="70" height="30" uuid="93eb71d7-a7a6-442e-a2cc-3506b3854ccb"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{expdate}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="290" y="90" width="74" height="30" uuid="0472dba7-8574-4bd2-bd6f-7c7329862a85"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="ce839cd3-8fe2-4987-8db1-b24876e254cb">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{batchlist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="74">
<textField>
<reportElement x="0" y="0" width="74" height="30" uuid="5e64886e-e3c4-4dfb-94c0-25abf57b6c76"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{batch}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="364" y="90" width="66" height="30" uuid="ea485a88-82fb-4c35-a5f4-ac5aeee9fdff"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="80698e51-9a06-446a-9f20-a07e315a4ec1">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{unitlist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="66">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="07f81482-f9a1-4d8b-aea4-2e72dd0c05b8"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{unit}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="429" y="90" width="51" height="30" uuid="9c591eea-e3e7-4139-aca1-971ab385cc81"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="9ee1f855-3abc-4818-ab16-f1a175de9c01">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{qtylist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="51">
<textField>
<reportElement x="0" y="0" width="51" height="30" uuid="57c13e54-42c3-400d-93b0-f14f60b41751"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{qty}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="480" y="90" width="76" height="30" uuid="1965ad12-e2d4-4b8c-a2a1-e6f981bd2238"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="tableDataset" uuid="92d5aeb4-83a9-4ca1-937f-04d93f796bb8">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{subtotlist})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="76">
<textField>
<reportElement x="0" y="0" width="71" height="30" uuid="d32c54e2-a4a8-4027-a5ed-1399a1b39d85"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{subtot}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
错误发生在字段pkgdatelist
错误
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : pkgdatelist
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1358)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1259)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1235)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1588)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:939)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:871)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:114)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at com.medicam.servlets.GenerateReportForPurchase.doPost(GenerateReportForPurchase.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodException: Unknown property 'pkgdatelist' on class 'class com.medicam.servlets.DataBean'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1313)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:762)
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:837)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
... 37 more
答案 0 :(得分:1)
您必须使用字段的名称作为bean中声明的字段。
因此,而不是<field name="pkgdatelist"...
使用<field name="p_pkg"...
等