![](/img/trans.png)
[英]Reference grailsApplication in resources.xml or other xml
[英]looking up beans from resources.xml into controller/service in groovy
我正在將groovy-grails與jasper報表結合使用來開發應用程序。 我需要根據其參數(例如從數據庫中檢索到的reportname / id,通過客戶點擊獲取該報告的參數)查找“ report bean”,它將作為resource xml中的report bean的屬性存儲到reportcontroller或reportservice中。 另外,我還必須“獲取”與此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>
會有很多這樣的豆子。
另外,所有報告的.jrxml文件都存儲在目錄中,我想將該位置關聯到報告上下文中,以便每當在前端單擊報告時,我都希望從上下文中將這些值查找到報告服務中/控制器來生成報告。 我知道我們必須在某個地方像ctx.getbean(reportId)一樣,但是我也想知道如何使用其他屬性(如模板位置,數據源,參數映射,reportid和jasperreportrenderrer對象)設置管理器bean。 因此,每次調用另一個報表時,都會重新使用此ReportManager bean進行加載,並且最好在用戶會話中持久保存。
您應該能夠執行以下操作:
import org.springframework.context.*
class MyService implements ApplicationContextAware {
ApplicationContext applicationContext
def getBeanByName( String name ) {
applicationContext.getBean( name )
}
}
這在grails Service
類中,但對於控制器也應如此
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.