cancel
Showing results for 
Search instead for 
Did you mean: 

getId() of the triggered UI Element

Former Member
0 Kudos

Hi,

how is it possible to get the ID of the a <b>triggered</b> FileDownload UI? In my application I create FileDownload-UIs by runtime.

myCode:


		for (int i = 0; i < node.size(); i++)
		{			
			IWDFileDownload fileDownload = (IWDFileDownload) 
				view.createElement(IWDFileDownload.class, String.valueOf(i));
			
			msg.reportSuccess("FileDownload ID: " + fileDownload.getId());
		}

regards,

Sharam

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hai ,

you are having two buttons you have binded one action for that two buttons , when you are firing that action you need to know which UI element get fired?

for this in action create a parameter named Id.

in wdModifyView

IWDButton butt=(IWDButton )view.getElement("Button1);

butt.mappingOfAction("Id",view.getId());

you can get the id from the action parameter.

regards,

Naga

Former Member
0 Kudos

Hi,

mappingOfAction is not possible for a fileDownload UI. A FileDownload UI has his own event handler, so I can't create it by my own.

regards,

Sharam

former_member182372
Active Contributor
0 Kudos

Sharam, what I would suggest in this case is to use linktoaction UI element and load content in action handler and open it in new window.

Former Member
0 Kudos

Your are assigning invalid IDs like 0,1,... IDs must start with a letter or an underscore (not recommended).

I doubt that you need these IDs later e.g. in an event handler, so you may simply pass null as ID.

Armin

Former Member
0 Kudos

Hi,

thank you for your replay. In my application I use a Web Dynpro to show all my documents as links from SAP Records Management. I don't know the number of the documents before so I have to generate the FileDonwnload UI's by run time.

I call the documents on demand by the generated Method "getOnDemandStream" (property of my attribute with the name "onDemandStream"=> readonly=true, calculated=true). In this method I use the piece of code below.

The problem is to get the appropriate URL from "elements.getURL". In "elements" I have my Model Class which contains all the information for the UI's.

So I have to know whitch FileDownload UI is triggered in order to pass by the correct URL. How can I get the information whitch UI is triggered? Is it possible to create an event handler for a FileDownload UI?


  public com.sap.tc.webdynpro.progmodel.api.IWDInputStream getOnDemandStream(IPrivateDPView.IContextElement element)
  {
.......
		URL url = new java.net.URL(  myElements.getUrl()  ); // But which element is triggered ???
		outBytes = new ByteArrayOutputStream();
.......
}

regards,

Sharam

Former Member
0 Kudos

Hi ,

Have not used it .. But in your code..


public com.sap.tc.webdynpro.progmodel.api.IWDInputStream getOnDemandStream(IPrivateDPView.IContextElement element)
  {
.......
		URL url = new java.net.URL(  myElements.getUrl()  ); // But which element is triggered ???
		outBytes = new ByteArrayOutputStream();
.......
}


(IPrivateDPView.IContextElement element)

gives you the element you want to use,,. Isnt it ?

Regards

Bharathwaj

Former Member
0 Kudos

Hi Bharathwaj,

yes, IEt_Doc_LinksElement elements gives me the element I want to use. I get a BAPI from my back-end system with a table parameter, i.e.:

ET_Doc_Links (0..n)

- url

- fileSize

- ....

- fileType

I Could get the right element with:

	  for (int i = 0; i < nodeSort.size(); i++)
	  {			  			
		IEt_Doc_Links_SortElement elements = nodeSort.getEt_Doc_Links_SortElementAt(i); <-- ?? which number (0..n)
}

the ID's of my FileDownload UI end with a number. If I get the number I can use the code above. With this number I can get the neccecary element from my node. But I don't know how to get the ID.

The other way is to get the ID of my current node attribute. I create for every FileDownload UI an attribute. An attributes ends also with a ID. This is the same ID like ("FileResource" + <b>i</b> ) which belongs to the appropriate "element".

creating attributes by run time for every FileDownload UI.

	for (int i = 0; i < node.size(); i++)
		wdContext.getNodeInfo().
			addAttribute("FileResource"+i,"com.sap.ide.webdynpro.uielementdefinitions.Resource");

regards,

sharam

Message was edited by:

Sharam Pourmir

Former Member
0 Kudos

Hi ,

As I understand , in your scenario .. you have a node data coming from the backend. It has details of filename and file content.

File names are displayed as links using a File Download ui.. so when a filedownload ui is clicked you want the particular files content to be loaded and downloaded.

Since , each filedownload element has a calculated attribute .. the getter of calcattribute will have the current clicked element reference passed as an argument.

So, in the getter method

Instead of ..

IEt_Doc_Links_SortElement elements = nodeSort.getEt_Doc_Links_SortElementAt(i); 

use


IEt_Doc_Links_SortElement elements = element; //element is the function parameter.this is for clarity .u can use the variable directly.
elements.getUrl();
elements.getType();
etc.,

And , please do explain the scenario and context of the question with proper code. You can see the lack of details in your actual question and your later replies.

Thanks and Regards

Bharathwaj

Former Member
0 Kudos

Hi Bharathwaj,

there is only one calculated attribute for all fileDownload element. And that is my problem.

i can not create them bevor because i don't know how many documents i get by run time. Thereby

i have to change the url-value in the method of my calculated attribute if a fileDownload UI was

triggered.

hier is my code:



  public void wdDoInit()
  {
	/** create attributes by runtime for every FileDownload UI. 	**/
	/** Because I don't know the number of the documents 		**/
	for (int i = 0; i < node.size(); i++)
		wdContext.getNodeInfo().
		   addAttribute("FileResource"+i,
		     "com.sap.ide.webdynpro.uielementdefinitions.Resource");

	
	for (int i = 0; i < node.size(); i++)
	{	
		/** elements (0..n) from my back-up system **/
		elements = node.getEt_Doc_LinksElementAt( i );				
	
		/** get the byteStream onDemand **/
		IWDAttributePointer attributePointer = 
			wdContext.currentContextElement().getAttributePointer("onDemandStream");
		
		IWDResource resource = WDResourceFactory.createResource(
				attributePointer,
				elements.getFile_Name(),
				WDWebResourceType.PDF
		);	
	 	
		wdContext.currentContextElement().setAttributeValue("FileResource" + i, resource );	

		IWDFileDownload fileDownload = (IWDFileDownload) 
			view.createElement(IWDFileDownload.class, "fileDownload"+i);

		fileDownload.bindResource( wdContext.getNodeInfo().getAttribute("FileResource" + i ) );
	}
}


  /** This method will be called if I click on my FileDownload Link. **/
  public com.sap.tc.webdynpro.progmodel.api.IWDInputStream 
  getOnDemandStream(IPrivateDPView.IContextElement element)
  {
	String url = null;

	for (int cout = 0; count < node.size(); count++){
		
		
		 /** If i get the current attribute: "fileResource+i" or the FileDownload-ID: "fileDownload+i" **/
		/**  which was triggered I can also get the "i" which is the identifier for the current "element". **/
		if (count == i){ 

			elements = node.getEt_Doc_LinksElementAt( i );
			url = elements.url();  -----------------|
		}						|
								|
	}							|
								|/** Where can I get i ??? **/					
	ByteArrayOutputStream outBytes = null;			|/** How can I get the current fileDownload-ID **/
	try{							|/** respectively the current attribute from my node **/
		String reader = null;				|
		URL url = new java.net.URL( url ); <------------|
		outBytes = new ByteArrayOutputStream();
		int contentLength = Integer.parseInt(elements.getFile_Size());
		ByteReader byteReader = new ByteReader( url.openStream() );
		
		while ( !(reader = byteReader.readLine()).equals("") ) {/***/}
				
		for (int count = 0; count < contentLength; count++){					
			outBytes.write( byteReader.read() );

	} catch (MalformedURLException malEx){
		msg.raiseException("MalformedURLException:      "+ malEx.getMessage(), false);
		return null;
	} catch (IOException ioEx){
		msg.raiseException("IOException:      "+ioEx.getMessage(), false);
		return null;
	}
	return WDResourceFactory.createInputStream( outBytes.toByteArray() );
}

Thank you for your help!

regards,

Sharam

former_member182372
Active Contributor
0 Kudos

Sharam, where exactly and for what purpose you gonna use ID of FileDownload UI element? It has no actions, data is bound to it directly and download is done automaticaly.