cancel
Showing results for 
Search instead for 
Did you mean: 

Validating FIle Upload UI

Former Member
0 Kudos

Hi,

I have a file upload ui element in WD java which is bound to iwdresource attribute of name resource. I have an upload button. WHen i click on upload when no file is uploaded, I must show an error message telling "Please select a file for upload". Can anyone assist mew with the code?? Also I want the resource name to be set in my file input ui element like this

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sakshi,

Check  resource is equal to null in side upload action.

if it is null then show message.

Use following code.

if(wdContext.currentContextElement().getResource==null){

      wdComponentAPI.getMessageManager().reportException("Please select file.");

}else{

}

Thanks,

Moreshwar

Former Member
0 Kudos

Hi moreshwar,

Thanks for the reply and it is working fine. Can you also tell how to set the name of the file uploaded in that fileinput UI element???

Former Member
0 Kudos

Dear Sakthi,

You can set the file name in  file input UI element( IPrivateFileUploadView.IContextElemen) like this.

public void onActionUploadFile(

com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent) {

//@@begin onActionUploadFile(ServerEvent)

IPrivateFileUploadView.IContextElement element = wdContext.currentContextElement();

...

// if a file in the FileUpload field exists

if (element.getFileResource() != null) {

IWDResource resource = element.getFileResource();

...

// set context attribute 'fileName' .

element.setFileName(resource.getResourceName());

...}

Read following document for better understanding.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4...

Thanks & Regards,

Patralekha

govardan_raj
Contributor
0 Kudos

hi Sakthi,

you can get the file name by using the

 

wdContext.currentFileUploadElement().getResource().getResourceName();

I dont think you can set name of a file being uploaded which already has a name, but u can change the name by creating another file .

use java code to create  a new file 'with new name with data from the file that you upload, and give a name to the file that you desire.

can u just breifly explain what exactly you wanted to achieve...

like just uploading file or upload file and store this file at other location with new name ?

Regards

Govardan

Answers (0)