Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
In Part-I: Print Web Dynpro Java applications using JasperReportsPart-I: Print Web Dynpro Java applications using JasperReports and Part-II: Print Web Dynpro Java applications using JasperReports of the blog series we discussed about JasperReports and developed a Java example to show how we can use them in code. In the final part of the series we will discuss how we can integrate the Jasperports in WebDynpro.

 

We have already developed the code for generating PDF report; please refer to Part-II for more information. Here we will only discuss about integrating it into WebDynpro application. We will create WebDynpro application, which will take name as input and generate PDF report accordingly.

 

 

You need to copy HelloReport.java and HelloReport.jrxml, to respective folders as shown in the Figure 1, from the project created as part of Part-II of this blog series. If you haven’t read Part-II please read it before going further. Also if you don’t find folders as shown in the figure create them accordingly. Similarly you should also copy your JasperReport jar files to lib folder.

Your WebDynpro application should contain a view as show in the Figure 1 above.  Create an input field and its text property should be bind to a context value attribute “name” of type string. Similarly create a button and bind its onAction event to GetReport action. If you go to Implementation tab, you will see a method created onActionGetReport, this method will be the center of our development. Rest of the form elements are just decoration. Code to be placed in your onActionGetReport method is:

public void onActionGetReport(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionGetReport(ServerEvent)
    try{
        HashMap data = new HashMap();
        data.put("NAME", wdContext.currentContextElement().getName());
        ArrayList dataList = new ArrayList();
        dataList.add(data);
         
        HelloReport report = new HelloReport(dataList);
        byte[] pdfData= report.getReportData();
        String reportFileName = "HelloJasperReport.pdf";            
    
        IWDResource pdfResource = WDResourceFactory.createResource(pdfData, reportFileName, WDWebResourceType.PDF);
        String urlToFile = pdfResource.getUrl(WDFileDownloadBehaviour.AUTO.ordinal());

        IWDWindow pdfWindow = wdComponentAPI.getWindowManager().createNonModalExternalWindow(urlToFile, "View Report");
        pdfWindow.setWindowPosition(5, 5);
        pdfWindow.setWindowSize(600, 600);
        pdfWindow.show();
     }catch(Exception e)
     {       
         wdComponentAPI.getMessageManager().reportException("Couldnot generate downloadble/print version: "+e.getMessage(), true);
     }   
    //@@end
  }


Now build your WebDynpro project and run it.

Suggestions:
You could deploy all the jars separately as a external library and use them in your subsequent projects. In this way you don’t have to copy jars to your lib folder and it will make the deployment archive smaller in size.

6 Comments