2013-12-18 60 views
0

我想在Struts 2.3.4中使用DynamicJasper 5.0.0。我使用下面的代碼來顯示PDF格式沒有爲名稱'success'映射的類型'dynamic-jasper'定義的結果類型

數據在動作類

try { 
    FastReportBuilder drb = new FastReportBuilder(); 
    DynamicReport dr = drb.addColumn("Size", "size", String.class.getName(), 30).setTitle("Size List Report").setSubtitle("This report was generateed at" + new Date()).setUseFullPageWidth(true) //make colums to fill the page width 
      .setPrintBackgroundOnOddRows(true).build(); 

    JRDataSource ds = new JRBeanCollectionDataSource(getSizeList()); 
    JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds); 
    JasperViewer.viewReport(jp); //finally display the report report [/CODE] 
} catch (Exception e) { 
    System.out.println("Exception"); 
} 
return SUCCESS; 

struts.xml的

<package name="expotpkg" extends="struts-default, json-default,jasperreports-default"> 
    <result-types> 
     <result-type name="dynamic-jasper" class="ar.com.fdvs.dj.webwork.DJResult"/> 
    </result-types> 

<action name="DownloadSizePdf" class="iland.work.SizesAction" method="fetchDJ"> 
      <result name="success" type="dynamic-jasper"> 
       <param name="dynamicReport">dr</param> 
       <param name="dataSource">sizeList</param> 
       <param name="documentName">Dynamic Report generated with struts 2</param> 
       <param name="parameters">params</param> 
       <param name="format">PDF</param> 
       <param name="layoutManager">classic</param> 
      </result> 
     </action> 
    </package> 

雖然運行此我收到以下錯誤

There is no result type defined for type 'dynamic-jasper' mapped with name 'success'. Did you mean 'dynamicJasper'? - result - file:/E:/Project/cxn/cnx/build/web/WEB-INF/classes/struts.xml:571:58 
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:653) 
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:387) 
    ... 20 more 

我已經包含以下jar文件 enter image description here

+0

你還沒有定義'dynamic-jasper'結果。 –

+0

@AleksandrM如何定義它 –

回答

0

添加這個配置到你的包

<result-types> 
    <result-type name="dynamicJasper" class="ar.com.fdvs.dj.webwork.DJResult"/> 
</result-types> 

<action name="DownloadSizePdf" class="iland.work.SizesAction" method="fetchDJ"> 
    <result name="success" type="dynamicJasper"> 
     <param name="dynamicReport">dr</param> 
     <param name="dataSource">sizeList</param> 
     <param name="documentName">Dynamic Report generated with struts 2</param> 
     <param name="parameters">params</param> 
     <param name="format">PDF</param> 
     <param name="layoutManager">classic</param> 
    </result> 
</action> 

ActionSupport類是包名com.opensymphony.xwork2下。錯誤發生在您與Struts2一起使用的插件的配置中,該插件與您使用的Struts版本不兼容。

+0

我已將上面的代碼包含在我的軟件包中但出現同樣的問題 –

+0

您有不同版本的動態碧玉。只能使用最新的5.0。嘗試將結果類型重命名爲'dynamicJasper'。 –

+0

不工作顯示錯誤'沒有爲名稱'success'映射的'dynamicJasper'類型定義的結果類型。你的意思是'dynamicJasper'?' –