on 04-05-2011 5:20 AM
Hello All,
I was trying to upload the XLS file using FILEUPLOAD Element and then transfer the data of File from XLS to Dynpro Table Element. Resource data type in not available in dictionary Type in my NWDS, I have bind the resource type property of FILEUPLOAD Element with Binary data type.
When I am geting the resource path like ".\temp\webdynpro\web\sap.com\usrupdt\Components\com.sap.UpdateUserRoles\TestFile.xls". When trying to read the file, it is giving me FILE NOT FOUNF exception.
WD INIT Method:
IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute(IPrivateUpdateUserRolesView.IContextElement.FILE_RESOURCE);
attInfo.getModifiableSimpleType();
FILE UPLOAD and READ Method:
boolean uploadStatus = true;
byte[] csvFileArray;
String CSVFilePath = null;
String CSVFileName = null;
IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute(IPrivateUpdateUserRolesView.IContextElement.FILE_RESOURCE);
IWDModifiableBinaryType FileResurceType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
IPrivateUpdateUserRolesView.IContextElement eleUpload = wdContext.currentContextElement();
try {
if (eleUpload.getFileResource() != null) {
String mimeType = FileResurceType.getMimeType().toString();
CSVFileName = FileResurceType.getFileName();
FileResurceType.setMimeType(WDWebResourceType.XLS);
FileResurceType.setFileName(CSVFileName);
CSVFilePath = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), CSVFileName);
Workbook w = Workbook.getWorkbook(new File(CSVFilePath));
Sheet sh = w.getSheet(0);
int cols = sh.getColumns();
int rows = sh.getRows();
String s1 = null;
String s2 = null;
for (int i = 0; i < rows; i++) {
s1 = sh.getCell(0, i).getContents();
s2 = sh.getCell(1, i).getContents();
}
} else {
uploadStatus = false;
this.ConfirmationPopUp("Please Select File to Upload.");
}
} catch (Exception e) {
throw new WDRuntimeException(e);
} finally {
return uploadStatus;
}
My question is:
1) Is it possible to read file Data, when File is uploaded using Binary Data Type.
2) Is there any sample code available for that?
3) If It is only possible using Resource dictionary Type, then how to add this library in web dynpro project.
Hi,
Have a look at the blog at http://wiki.sdn.sap.com/wiki/display/WDJava/UploadingexcelfileusingWebDynproforJava
It has a pretty thorough step-by-step explanation on how to upload and read an Excel file.
Please note the above blog uses the JExcelApi (http://www.andykhan.com/jexcelapi/) but it seems from your code you already use it as well.
Hope this helps,
Robin van het Hof
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm not sure if I understand correctly... if you need to include the jexcelapi jar files to you WD project, I would recommend creating a new External Library DC, which contains the jar files (see http://help.sap.com/saphelp_nw70/helpdata/en/5a/2e2f4234135433e10000000a155106/frameset.htm on how to create an External Library DC)
Then add the public part to your applications Used DC
Hope this explains
Robin
Thanks Robin for all your support.
I am able to use jexcelapi jar files by adding it as an External Library DC.
But My problem is lying with FILE UPLOAD Element. It has two properties.
1) Data ->> Should be binded with View Context Element of Type RESOURCE
2) FileName ->> Should be binded with View Context Element of STRING
But Type Resource is not available in list of com.sap.ide.webdynpro.uielementdefinitions in Local Dictionary.
So I have binded the Data property of FILE UPLOAD Element with View Context Element of Type BINARY.
Do you have any Idea, How to transfer the XLS File Data to dynpro table in this type of scenario.
Many Thanks In Advance.
Regards,
Pankaj Singh
Hello Robin,
I am using the following version of NWDS.
Version: 2.0.19
Build id: 200610270428
JDK Version is : j2sdk1.4.2_18
Is it the right version Or I need to upgrade my support pack.
If It is the right version version. Then Do I need to add some additional DC from from sap.com_SAP_BUILDT_1 / sap.com_SAP-JEE_1 as used DC to get Resource datatype in UIELEMENT definition List.
Regards,
Pankaj Singh
Hi Govindu,
I'm afraid that's not true. See API for IWDResource at http://help.sap.com/javadocs/nwce/current/wdr/com.sap.wdr/com/sap/tc/webdynpro/services/sal/datatran... :
This interface represents a general resource with a name a MIME-type and binary data. Its binary representation is an InputStream that can be read. Each resource is available by a specific URL. This type can be bound to the property resource of the UI elements FileUpload and FileDownload.
Note that Web Dynpro does not hold a reference to the resource. The application is required to hold one itself. This is typically done via a context attribute with a predefined data type "com.sap.ide.webdynpro.uielementdefinitions.Resource".
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.