[英]Using custom class as a parameter/field in J2EE application
I am trying to pass the custom object value to Jasper report, I am using compiled jasper ie .jasper
file. 我正在尝试将自定义对象值传递给Jasper报告,我正在使用已编译的jasper即
.jasper
文件。
Passing the parameter in jrxml 在jrxml中传递参数
<parameter name="STUDENT_ID" class="abc.xyz.Student"/>
Trying to access the parameter in jrxml 尝试访问jrxml中的参数
<textField>
<reportElement x="156" y="100" width="403" height="20" uuid="20cc6538-41d9-4fe5-ba43-e3152b073e10"/>
<textFieldExpression><![CDATA[": "+$P{STUDENT_ID}.getId()]]></textFieldExpression>
</textField>
Structure: 结构体:
jasper/
temp.jasper
WEB-INF/
classes/
lib/
web.xml
Service class 服务等级
Student student = session.get("student")
HashMap<String, Object> map = new HashMap<String, Object>(1);
map.put("STUDENT_ID", student);
print = JasperFillManager.fillReport(ServletActionContext.getServletContext().getRealPath("/jasper/temp.jasper"), map, new JREmptyDataSource());
Student
class will vary student to student, Student class has the fields id
and name
with getters and setters
, but somehow values are not getting rendered on generated PDF file. Student
班级会因学生而异,学生班级的id
和name
带有getters and setters
,但在生成的PDF文件中不会以某种方式呈现值。
How to access the Student object? 如何访问学生对象?
At first view I can't see nothing wrong with your code, but if you are passing an empty data source, be sure to not place the field you want on Datails band. 乍一看,我的代码看不到任何问题,但是,如果您传递的是空数据源,请确保不要将所需字段放在Datails波段上。 Without data source, this band is not rendered.
如果没有数据源,则不会渲染此频段。 Test it putting the field on Title band, for example.
例如,对其进行测试,然后将该字段放在“标题”乐队上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.