cancel
Showing results for 
Search instead for 
Did you mean: 

File upload....How to find the user entered any file or not

Former Member
0 Kudos

Hi Team,

I am working on with file upload UI.

Some times without clicking on browse button, I mean without entering any file they are cliking on upload button, which is giving the exception.

I know there is no action for UI element, Then how to resolve this?

I just control the user, not to press the upload button without entering any file name there?

How to resolve this?

regards,

Bala

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This code will solve ur problem.

public void onActionUploadFile(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionUploadFile(ServerEvent)

IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateFileUploadDownloadView.IContextElement.FILE_RESOURCE);

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attributeInfo.getModifiableSimpleType();

IPrivateFileUploadDownloadView.IContextElement element = wdContext.currentContextElement();

if(element.getFileResource() !=null)

{

try

{

String mimeType = binaryType.getMimeType().toString();

byte[] file = element.getFileResource();

//element.s

wdComponentAPI.getMessageManager().reportMessage(IMessageFileUploadDownloadComp.SF__UPLOAD,new Object[] {binaryType.getFileName()},false);

}

catch(Exception e)

{

throw new WDRuntimeException(e);

}

}

else

{

wdComponentAPI.getMessageManager().reportMessage(IMessageFileUploadDownloadComp.NO__FILE,new Object[] {" "},true);

}

//@@end

}

Here "fileresource" is context attribute name

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi Sunaina,

I tried it already, But it's giving me the null pointer exception at element.getFileResource() line if the file is not selected.

I don't know why it is happening like this.

Any idea?

Regards,

Bala

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

In my case it is working fine. try to copy the same code.if it is null then the control will go to else part.

Do u have any idea on Message pool ?

In my code SF__UPLOAD and NO__FILE are Message keys.

create these 2 message keys and copy the same code.

Regards,

Sunaina

Former Member
0 Kudos

I tried ,All that i am not finding why it is giving the null pointer exception.

Any one has any idea?

Regards,

Bala

former_member194668
Active Participant
0 Kudos

Hi Bala,

The only reason it could happen is when the element itself is null. Kindly paste ur non-working code here and tell us abt ur context structure. So that we can be of more use to you.

-Aarthi

Former Member
0 Kudos

Can you please clarify,

What do you mean by element itself is null?

FileResource is a normal context attribute with resource type.

It is not under any node.

Regards,

Bala

Former Member
0 Kudos

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

try {

String mimeType = binaryType.getMimeType().toString();

byte[] file = element.getFileResource();

...

...

wdContext.currentcontextelement.setuploadbuttonenable("true");

}

} catch (Exception e) {

throw new WDRuntimeException(e);

}

}

else

{

wdContext.currentcontextelement.setuploadbuttonenable("false");

}

I think this can help you?

Former Member
0 Kudos

Hai bala,

I am having a suggestion. You can try set the upload button as disabled initially. you can enable it only after the user clicks the browse button. I am new to this web dyn pro. so this is my idea. if it was wrong inform me.