cancel
Showing results for 
Search instead for 
Did you mean: 

File Chooser in WebDynpro

Former Member
0 Kudos

Hi,

I am quite new to WebDynpro. And I have the following task:

In a WebDynpro view, on click of a button I should be able to pop up a file chooser dialogue and allow the user to select a file (.xls) and then on selection of the file I should be able to get InputStream object of the selected file in a WebDynpro view so that i can use it for reading/writing purpose.

Can anybody help me in this regard.

thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Did u create/design your Popup window..? Did u write the code for calling this window..?

if u have done both , then create an attribute of type resource in your pop-up layout and bind it to an Input field.This will help you to brose for a file path.

Former Member
0 Kudos

Hi James,

No I have not created any PopUp window or have not written code to call the window. Can you please provide me with some help to create the pop up window to browse for the file. Actually FileUpload UI element comes with a TextField and a Browse button. I need the functionality of the Browse button but I dont want the TextField to be displayed.

This is what exactly i need to do:

There is a DecisionTable which is a table in a WebDynpro view, and I have API methods that will take instance of DecisionTable and InputStream and will convert the DecisionTable into .xls file and viceversa.

Now I want the user to click on a button "Import" which will allow user to select a ".xls" file from the client machine and then once the user okays the file, I should get an InputStream for the file so that i can create the DecisionTable in the view, using the API method to convert .xls to DecisionTable

On clicking another button "Export" I should be able to ask the user to provide a location where to store the resulting .xls file created from the DecisionTable

Thanks in advance

former_member185086
Active Contributor
0 Kudos

Hi

1. Code for Open a popup

IWDWindowInfo windowInfo = wdComponentAPI.getComponentInfo().findInWindows("TestWin");

IWDWindow windowManager = wdComponentAPI.getWindowManager().createModalWindow(windowInfo);

wdContext.currentContextElement().setWindowInstance(windowManager);

windowManager.setTitle("Rss Feed");

windowManager.setWindowSize(600, 300);

windowManager.show();

2. Put any view with Upload UI Element insight the window say TestWin

3.Open this window dialog method at Import Button of table this pop up will open

4. When u press the upload u need all xls data in some node so code for that

if (element.getFileResource() != null)

{

IWDResource resource = element.getFileResource();

if (resource.getResourceType().getFileExtension().equals("xls"))

{

try

{

InputStream inputStream = resource.read(false);

Workbook workbook = Workbook.getWorkbook(inputStream);

Sheet sheet = workbook.getSheet(0);

int number_user = sheet.getRows() - 1;

for (int i = 1; i < sheet.getRows(); i++)

{

IPrivateUserDataView.IUsersFromFileDataNodeElement userElement = wdContext.createUsersFromFileDataNodeElement();

parseFileData(i, sheet, userElement);

}

workbook.close();

} catch (Exception ex)

{

}

} else

{

wdComponentAPI.getMessageManager().reportWarning("Please select valid file type.");

wdContext.currentUploadFileInformationElement().setIsBulkOperation(false);

wdContext.currentUploadFileInformationElement().setFileInformationVisibility(WDVisibility.NONE);

}

}

Code for parseFileData(i, sheet, userElement);

public void parseFileData( int row, jxl.Sheet sheet, com.incture.admincomp.wdp.IPrivateUserDataView.IUsersFromFileDataNodeElement userElement ) {

//@@begin parseFileData()

for (int i = 0; i < sheet.getColumns(); i++)

{

if (i == 0)

userElement.setUserId(sheet.getCell(0, row).getContents());

if (i == 1)

userElement.setPassword(sheet.getCell(1, row).getContents());

if (i == 2)

userElement.setLastName(sheet.getCell(2, row).getContents());

if (i == 3)

userElement.setFirstName(sheet.getCell(3, row).getContents());

if (i == 4)

userElement.setPhone(sheet.getCell(4, row).getContents());

if (i == 5)

userElement.setFax(sheet.getCell(5, row).getContents());

if (i == 6)

userElement.setEmail(sheet.getCell(6, row).getContents());

}

wdContext.nodeUsersFromFileDataNode().addElement(userElement);

wdContext.nodeUsersFromFileDataNode().setLeadSelection(-1);

5. After this Close the pop up. And this is solution for Import functionality

6 For Export : Check [this|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3596] [original link is broken] [original link is broken] [original link is broken]; thread

Hope it help you

Best Regards

Satish Kumar

Former Member
0 Kudos

Hi Santhosh,

U can follow the above code given by Satish.

Get back if u are stuck up some where.

Former Member
0 Kudos

Hi Satish and James,

Thanks for the prompt reply. I will try this solution and will definitely get back.

Thanks and Regards,

Santosh Giri

Former Member
0 Kudos

Hi Satish,

The solution that you have provided really helped me completing my task. Thanks for the help to all others too.

Thanks and Regards,

Santosh Giri

Former Member
0 Kudos

Santosh,

I don't see any code in this post (by Satish). Could you please share it

Regards,

Samba

Answers (2)

Answers (2)

former_member185086
Active Contributor
0 Kudos

Hi

take the help from following threads

1.[xls File Upload|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4591] [original link is broken] [original link is broken] [original link is broken];

1[File Upload|;

2.[File Upload Example|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71]

Hope it help you

Best Regards

Satish Kumar

Former Member
0 Kudos

Hi Satish,

Could you please share the code. Even i have to implement the same functionality, on clicking a button a file chooser should open

Thanks in advance!

Regards,

Samba

Former Member
0 Kudos

Hi,

Please look into the below thread. It explains the same.

Thanks,

Prasanthi