on 08-13-2008 10:18 AM
Hello!
I have a an EJB which delivers a String, which I want to be saved by the user in my WD project.
So I need to convert the incoming String to binary type in my context.
According to the tutorial "Uploading and Downloading Files" I created an event handler for a button with the following code:
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateXmlManagerView.IExportFileElement.FILE_RESOURCE);
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();
String outStream = XmlHandlerFacade.getInstance().exportXml();
wdContext.currentExportFileElement().setFileResource(outStream.getBytes());
binaryType.setFileName("myOutput.xml");
binaryType.setMimeType(WDWebResourceType.XML);
This implementation just causes a NullPointerException.
When I only try to implement the conversion of the String to a Byte-Array like this...
String outStream = XmlHandlerFacade.getInstance().exportXml();
wdContext.currentExportFileElement().setFileResource(outStream.getBytes());
...there is an IllegalArgumentException:
java.lang.IllegalArgumentException
at com.sap.dictionary.runtime.DdTypeBinary.format(DdTypeBinary.java:61)
at com.sap.tc.webdynpro.clientserver.data.DataContainer.doFormat(DataContainer.java:1402)
at com.sap.tc.webdynpro.clientserver.data.DataContainer.getAndFormat(DataContainer.java:1092)
at com.sap.tc.webdynpro.clientserver.data.DataContainer.getAndFormat(DataContainer.java:1064)
at com.sap.tc.webdynpro.clientserver.uielib.standard.impl.FileDownload._getData(FileDownload.java:81)
... 84 more
Anybody knows how to do it right?! I imagine that it can't be so difficult...
Thanks,
Ramó
Try this way,
String test = XmlHandlerFacade.getInstance().exportXml();
IWDResource resource = WDResourceFactory.createResource( test.getBytes(), "test", WDWebResourceType.XML);
wdContext.currentExportFileElement().setFileResource( resource);
Regards
Vinod V
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your answers. I tried to implement like you said, but the NWDS says, that
wdContext.currentExportFileElement().setFileResource(resource);
is not applicable for IWDResource arguments - instead of this only for byte[].
Perhaps this way is not available in my version? I'm working with NWDS 7.0 SP08 (actually it is not possible to upgrade to another version).
The code line
byte[] test = outString.getBytes();
doesn't cause an exception.
It happens only, when I want to do
wdContext.currentExportFileElement().setFileResource(test);
Edited by: Ramón Diegel on Aug 13, 2008 1:54 PM
Hi
I have tried this code and found working
The Context Value Attribute is of type Resource
// init method
String test = "testing for";
IWDResource resource = WDResourceFactory.createResource( test.getBytes(), "tst", WDWebResourceType.XML);
wdContext.currentContextElement().setResource( resource);
// Download action
IWDWindow window = wdComponentAPI.getWindowManager()
.createExternalWindow( wdContext.currentContextElement()
.getResource().getUrl( 0), "Test", false);
window.open();
Result
Opens a new Window containing the string testing for in XML form
I am using NWDS 7.0 SP 09.
Regards
Vinod V
Hi,
First check if "outStream" is null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi! yes, the "real" implementations is surrounded by an IF:
if (outStream == null) {
wdThis.wdFirePlugToErrorView("XML could not be generated!\nUnknown error.", "XML Export");
} else {
wdContext.currentExportFileElement().setFileResource(outStream.getBytes());
}
The simple output of the string itself works.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
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.