Show TOC Start of Content Area

Procedure documentation Loading the InputStream at FileDownload on Demand  Locate the document in its SAP Library structure

With the FileDownload element, the content of the file is loaded into the context when the page is built, which happens in the wdDoInit method. If the FileDownload element is used, for example, in a table, this can lead to performance problems.

For this reason, it is possible to delay loading the file content into the context until the download is triggered, that is, when the user actually clicks the FileDownload element. The example below describes the procedure you can use to load data into the context only in the moment you really need it.

Prerequisites

      You have created a Web Dynpro DC with component and view and you have included a FileDownload element into the view.

      In the context of the view, you have created a value node named resourceNode.

      In this value node, you have created a value attribute of type com.sap.ide.webdynpro.uielementdefinitions.Resource, as described in Binding resource Property.

Procedure

...

       1.      In the context of your view, under the value node resourceNode, create a value attribute, name it onDemandStream and confirm with Finish.

       2.      Switch to the Property window, and for the type property click . The Type Selection wizard is started.

       3.      Select Java Simple Type, click Browse… and in the next window in the field Choose a Type enter com.sap.tc.webdynpro.progmodel.api.IWDInputStream. Confirm twice with Okay.

       4.      Set the readonly property to true.

       5.      Set the calculated property to true. A calculatedAttributeGetter method with the name     getOnDemandStream is created.

       6.      To generate the InputStream, include this method into the following code:

IWDInputStream stream = null;

try {

   String path = WDURLGenerator.getResourcePath(

   wdComponentAPI.getDeployableObjectPart().getWebModule(),"<name of download file>");

   stream = WDResourceFactory.createInputStream(new
  
   FileInputStream(path));

   } catch (Exception ioExp) {

}

return stream;

       7.      The two attributes resource and onDemandStream must be linked.

Switch to method wdDoInit and enter the following code:

IPrivateLoadOnDemandView.IResourceNodeElement elem =

       wdContext.currentResourceNodeElement();

       //getting the attributepointer of the calculated attribute

       IWDAttributePointer attributePointer =

          elem.getAttributePointer("onDemandStream");

       IWDResource resource =

          WDResourceFactory.createResource(

          attributePointer,

          "<name of the file>",

          WDWebResourceType.<type of the file>);

       // setting value to the bound attribute

       elem.setResource(resource);

       8.      Save your data.

Result

You have created a FileDownload element whose data will be loaded into the context only when the download is actually triggered.

 

End of Content Area