在groovy中从resources.xml查找bean到控制器/服务中
我正在使用 groovy-grails 和 jasper reports 来开发一个应用程序。我需要根据其参数查找“报告 bean”(例如从数据库检索的报告名称/id,我将从客户点击中获取) - 它将作为报告 bean 的属性从 resources.xml 存储到报告控制器或报告服务中。另外,我还必须“获取”与此 id 和参数 Map 相关的 jrxml 模板,两者都定义为 bean 中的属性。我需要知道我们如何才能实现这一点,以及我们是否需要在 xml 中定义任何管理这些报告 bean 的“管理 bean”。 例如,报告 bean 将如下所示:
<bean id="DeptReport" class="com.myapp.reporting.domain.Report">
<property name="reportName" value="Dept Report"/>
<property name="reportFiles">
<map>
<entry key="JasperPrint" value="DeptRoles.jrxml"/>
</map>
</property>
<property name="promptforparameter" value="true"/>
<property name="parameter" value="department_id"/>
<property name="displayName" value="report.deptReport.name"/>
</bean>
将有很多这样的 bean。
此外,所有报告的 .jrxml 文件都存储在一个目录中,我想将该位置连接到报告上下文中,以便每当在前端单击报告时,我想从上下文中查找这些值到报告服务中/控制器生成报告。我知道我们必须在某个地方执行类似 ctx.getbean(reportId) 的操作,但我也想知道如何使用其他一些属性(例如模板位置、数据源、参数映射、reportid 和 jasperreportrenderrer 对象)设置管理器 bean。因此,每次调用另一个报表时都会加载此 ReportManager bean,并重复使用它,并且理想情况下会在用户会话中保留该 bean。
I am using groovy-grails with jasper reports to develop an app. I need to lookup 'report bean' based on its parameter (like reportname /id retrived from database, which I will get from customer click) - which will be stored as a property of report bean from resources.xml into either the reportcontroller or reportservice. Also I have to 'get' the jrxml template related to this id and the parameter Map, both defined as properties in the bean. I need to know like how can we achieve this and do we need to define any 'managing beans' in the xml which manage these report beans.
So for example the report bean will look like as follows:
<bean id="DeptReport" class="com.myapp.reporting.domain.Report">
<property name="reportName" value="Dept Report"/>
<property name="reportFiles">
<map>
<entry key="JasperPrint" value="DeptRoles.jrxml"/>
</map>
</property>
<property name="promptforparameter" value="true"/>
<property name="parameter" value="department_id"/>
<property name="displayName" value="report.deptReport.name"/>
</bean>
There will be many beans like this.
Also the .jrxml file for all reports are stored in a directory and I want to wire that location into the reporting context so that whenever a report is clicked on the front end I want to look up these values from the context into the report service/controller to generate the report. I know we have to do like a ctx.getbean(reportId) somewhere but I also want to know how to setup a manager bean with some other properties like template location, datasource, parameter map, reportid and a jasperreportrenderrer object. So this ReportManager bean is loaded reused every time there is a call for another report and persisted across a user session ideally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该能够做这样的事情:
这是在 grails
Service
类中,但对于控制器来说也是如此You should be able to do something like this:
That's in a grails
Service
class, but the same should hold true for a controller