且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

来自字符串的数据源

更新时间:2023-09-21 13:07:40

您的字段元素不包含XML路径表达式。试试这个:

Your field elements do not contain XML path expressions. Try this:

<field name="firstName" class="java.lang.String">
    <fieldDescription><![CDATA[DATA/ROW/firstName]]></fieldDescription>
 </field>
 <field name="lastName" class="java.lang.String">
   <fieldDescription><![CDATA[DATA/ROW/lastName]]></fieldDescription>
 </field>
 <field name="code" class="java.lang.Integer">
   <fieldDescription><![CDATA[DATA/ROW/code]]></fieldDescription>
 </field>

此外,我有时会采用一些小技巧。在 JRXmlDataSource 周围创建一个包装器类,在Jasper检索它们时转储字段的内容:

Also, there's a little trick I employ sometimes. Create a wrapper class around JRXmlDataSource that dumps the contents of the fields as Jasper retrieves them:

package <your package here>;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.data.JRXmlDataSource;

public class MyXmlDataSource extends JRXmlDataSource {

    public MyXmlDataSource(String x, String y) throws JRException
    {
        super(x,y);
    }

    public Object getFieldValue(JRField jrField) throws JRException {
        Object ret = super.getFieldValue(jrField);
        System.out.println(ret);
        return ret;
    }
}

然后,而不是实例化 JRXmlDataSource ,实例化 MyXmlDataSource 。这将告诉您Jasper从您的XML中检索哪些元素。

Then, instead of instantiating JRXmlDataSource, instantiate MyXmlDataSource instead. This will let you know which elements are being retrieved by Jasper from your XML.