on 03-23-2007 9:22 AM
I have one table, preceded by a radio button for each row. After checking the radio button when the user press "DOWNLOAD" button, the corresponding file should download.
I may get the url after some days. But could any one give me the generalized code for this.
I repeat.... selecting a radio button ad clicking a action button should cause the file download mechanism.
Hi Pradeep,
You want to download a file when some condition is satisfied (in ur case radio button and download button). Following is the code given to download a file (taken form standard help provided by NWDS)
// The FileDownload UI element requires:
IWDAttributeInfo attInfo = wdContext.nodeRoot().getNodeInfo().getAttribute("FileDownLoad");
binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
// in addition the FileDownload UI element needs for defined resource types
binaryType.setFileName("Snow Trees.jpg");
binaryType.setMimeType(WDWebResourceType.JPG_IMAGE);
//The FileDownload UI element needs for undefined resource types
binaryType.setFileName("Snow Trees.xcc");
binaryType.setMimeType(new WDWebResourceType("xcc", "", true));
This way you can download any file.
XXXXXXXXXXXXXXXXXXXXXXXXXXX.
Abhinav
Message was edited by:
Armin Reichert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pradeep,
You can easily use File Download UI element.
Simply bind the onSelect property of the radio button to an action and in that action write the code to intialize the context which is storing the binary data of the file with the appropriate file. The sample code is given below
<b>IWDAttributeInfo attInfo =
wdContext.currentContextElement().node().getNodeInfo().
getAttribute("PdfSource");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;
binaryType.setFileName("TravelRequest.pdf"); // Set file name
binaryType.setMimeType(WDWebResourceType.PDF); // set the mime type
String fileName = <Your File path>
/
/ path to the source file
/* converts the binary file to a byte array and moves it to the text element */
contry
{
File file = new File(fileName);
FileInputStream in = new FileInputStream(file);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int length;
byte[] part = new byte [10 * 1024];
while ((length = in.read(part)) != -1)
{
out.write(part, 0, length);
}
in.close();
wdContext.currentContextElement().
setPdfSource(out.toByteArray());
} catch(Exception e)
{
throw new WDRuntimeException(e);
}</b>
Regards
Sid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi sid,
Right now i dont have J2ee server to deploy and check wheter your code is working or not for me. But one basic doubt, am I need to use "file download" UI element or not? If yes, the file download UI will be a like a link( on which we need to click to download). But i need this action will perform in a button not as a link.
could you help me in regards.
Hi Pradeep,
If you dont want to use the File Download UI element then you can write the following code in the onAction associated to your button:
first read the file as mentioned in my code and then
<b>String FileName = file.getAbsoluteFile().getName();
IWDCachedWebResource webResource = WDWebResource.getWebResource(fileData, WDWebResourceType.PDF);
window = wdComponentAPI.getWindowManager().createExternalWindow(webResource.getURL(), "Report", false);
window.open();</b>
You can refer to this link too.
Do reward points if it helps.
Regards
Sid
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.