cancel
Showing results for 
Search instead for 
Did you mean: 

Filedownload from a table

Former Member
0 Kudos

Hi WD fellows,

I need do implement a file download from a table in NW04s. Looks like there where some changes with the 04s release so I followed the description on help.sap.com here:

http://help.sap.com/saphelp_nw2004s/helpdata/en/3a/9c6e42f50b0d53e10000000a155106/frameset.htm

Work well for one row in the table but with multiple table entries I always get the same file for download. I expect there is some difference in the initialization than described in the documentation.

Can some give me a hint how to implement this for a table?

Thanks and best regards,

ok

Accepted Solutions (0)

Answers (3)

Answers (3)

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Just wanted to share my newly found wisdom to the problem. In the end it wasn't more than a simple loop to catch all table entries.

Here is the changed wdDoInit from the view:


  public void wdDoInit()
  {
    //@@begin wdDoInit()
    IAdviceRecordNode node = wdContext.nodeAdviceRecord();
    for (int i=0; i<node.size(); i++) {
        IPrivateAvisListView.IAdviceRecordElement element =
               node.getAdviceRecordElementAt(i);

        //getting the attributepointer of the calculated attribute.
        IWDAttributePointer attributePointer =
            element.getAttributePointer(IPrivateAvisListView.IAdviceRecordElement.ON_DEMAND_STREAM);
    
        // Build name of file to download.
        String filename = "Avis-" + element.getBillDate().toString() + ".pdf"; 

        IWDResource resource = WDResourceFactory.createResource(
            attributePointer,
            filename,
            WDWebResourceType.PDF);

        element.setResource(resource);
    }

It still somehow doesn't use my given filename but that's another problem to figure out.

ok

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Oliver,

regarding your filename issue. This should work. Do you create the same filename within the for loop twice/many times? Whate filenames of your on-damnd resource are sent to the client?

Regards, Bertram

sid_sunny
Contributor
0 Kudos

Hi oliver,

it is probably because you are not intializing the resource property of the filedownload ui correctly to learn the usage of file download read the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f5d3c40a-0801-0010-55b7-9e3b01745a40">Tutorial no 39</a> and properly intialize the resource property of the filedownload UI

Regards

Sid

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thanks for that, but I'm on 04s and the tutorial is for NW04 and doesn't deal with the resource property. Bertram Ganz released a new tutorial for 04s but that doesn't seem to be available yet.

ok

sid_sunny
Contributor
0 Kudos

Hi oliver,

if you want i can mail you the new one too as i have forgotten the online link.

I found the new doc link

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71">New Tutorial</a>

Regards

Sid

Message was edited by:

siddharth chauhan

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

It's available here:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a...

I meant the referenced sample project isn't available yet. The article itself didn't helped me that much.

sid_sunny
Contributor
0 Kudos

Hi oliver,

I had implemented it if you want I can send you the zip file of the project.

Regards

Sid

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

That would be great. I've sent you my mail address to yours @tcs.

Thanks in advance!

ok

sid_sunny
Contributor
0 Kudos

Hi Oliver,

has dropped you the project on your mail id.

XXXXXXXXXXXXXXXXXXXXXXXXXX

Regards

Sid

Message was edited by:

Armin Reichert

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Siddharth,

it was helpful but didn't solved my original problem.

I'm still looking for a solution to have a file download in a table for each row.

Maybe to elaborate a little more on this...

This is the code for wdDoInit:


    //@@begin wdDoInit
	IPrivateAvisListView.IAdviceRecordElement elem =
		   wdContext.currentAdviceRecordElement();

	//getting the attributepointer of the calculated attribute
	IWDAttributePointer attributePointer =
		elem.getAttributePointer("onDemandStream");
	
	IWDResource resource = WDResourceFactory.createResource(
		attributePointer,
		"Avis.pdf",
		WDWebResourceType.PDF);

	// setting value to the bound attribute
	elem.setPdfResource(resource);
	wdContext.currentContextElement().setPdfImage("pdf16x16.gif");
    //@@end

Here is the code from the calculatedAttributeGetter method:


    //@@begin getPdfResourceOnDemandStream(IPrivateAvisListView.IPdfResourceElement)
	IWDInputStream stream = null;
	try {
		// Load PDF data for current context element.
		IAdviceRecordElement adviceRecordElement = 
			wdThis.wdGetSupplierPortalController().wdGetContext().currentAdviceRecordElement();

		wdThis.wdGetSupplierPortalController().loadPdfRecord(adviceRecordElement.getPdfId());

		// Get data stream from PDF.
		stream = WDResourceFactory.createInputStream(
			wdThis.wdGetSupplierPortalController().wdGetContext().currentPdfRecordElement().getPdfData().toByteArray());
	}
  	catch (Exception e) {
	  wdComponentAPI.getMessageManager().reportException(e.toString(), true);
	}
	return stream;
    //@@end

It's a modified version of the mentioned tutorial and works fine for the first table row but for all other rows it won't get called.

How do I have to modify the wdDoInit to catch all table rows?

Thanks,

ok

sid_sunny
Contributor
0 Kudos

Hi Oliver,

I am not very sure as the given code is very abstract but whatever I could learn from it is that you are reading the first file and setting the PDFsource attribute binded to the resource property of download UI element. now it will always download the same file as whenever you are selecting any other row of the table which points to some other pdf file attributes you are not reading that file and re intializing the PDFsource context binded to resource property.

So I would suggest you to implement the code of reading the file in an action binded to the onLeadSelect property of the Table UI element.

I hope this helps.

Regards

Sid

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Siddharth,

I tried the onLeadSelection event but because there is a FileDownload element the selection doesn't change. That approach doesn't work for me here.

Regards,

ok

sid_sunny
Contributor
0 Kudos

Hi Oliver,

Does your table itself has a column with FileDownload UI elements in it. I dont think you have choosen this approch just to download different files and if you have I would suggest you to have one common FileDownload UI element and download the file selected in the table.

Regards

Sid

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Oliver,

you wrote "the article itself didn't help me that much". As the author of this article I'm interested in how to improve it so that it better illustrates this technical topic. Is the missing sample project (I will publish a WebLog very soon where you can find the URL of this ZIP file, even I don't know it, actually) the reason for not getting the picture with the article only? Is the article unclear?

In advance, thanks for your reply.

Regards, Bertram

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Bertram,

nice to see you here getting back to this issue and taking care about the stuff you're involved. I really appreciate it.

The article about File Upload/Download is very valuable information on this topic and a good read for everybody involved in it and I can only recommend it. It didn't helped me here, because I already had the insight into IWDResource from help.sap.com and couldn't find any additional information in that article about using it in a table. That's why I came here to SDN but as you already know you did a great job pushing me into the right direction.

It would of course be helpful to have the sample project available once the article is on SDN but even without it the article is a good guide.

Thanks,

ok

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Oliver,

thanks for your answer but I assume that we do not refer to the same article.

I wrote two documents on Uploading and Downloading Files in NW04s:

  • Tutorial: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71">Uploading and Downloading Files in Web Dynpro Java - NW04s</a>

  • Article: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0e10426-77ca-2910-7eb5-d7d8982cb83f">Uploading and Downloading Files in Web Dynpro Tables</a>

<b>NEW: And here are the URLs to the related sample project ZIP Files:</b>

  • Initial Template Project: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/30398c47-40a9-2910-4aae-cec9b96d56b0">TutWD_FileUpDownload_NW04s_Init.zip</a>

  • Final Project: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40db4a53-41a9-2910-d4a2-9c28283f6658">TutWD_FileUpDownload_NW04s.zip</a>

Is it possible that your comment <i>".... I couldn't find any additional information in that article about using it in a table"</i> refers to the Tutorial PDF but not to my special article dealing with on-demand file download in tables: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0e10426-77ca-2910-7eb5-d7d8982cb83f">Uploading and Downloading Files in Web Dynpro Tables</a>? I hope so, otherwise my efforts would have been in vain.

Best regards, Bertram

oliver
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Bertram,

yes, my comment referred to the Tutorial <i>Uploading and Downloading Files in Web Dynpro Java - NW04s</i>. I wasn't aware about your new article at that point. Otherwise it would have given me a much better insight into the matter, from what I've seen so far.

Thanks for pointing to the new article here. This way now it's indexed, search able content and easy to find for everybody with similar problems.

Your efforts are highly appreciated from my side;)

Best regards,

ok

Former Member
0 Kudos

Hi,

You will get different files for download on different table rows if the "resource" property of the Filedownload UI element points to different data.

Regards,

Satyajit.