cancel
Showing results for 
Search instead for 
Did you mean: 

File Upload Error : Object could not be found in cache, key is null!

Former Member
0 Kudos

I am having this problem. when I attach a file and press submit button, it gave me

"Object could not be found in cache, key is null !"

In my ViewController context I have Invoice_DOC attribute (binary, fileupload)

and that is mapped to ComponentContoller.attribute(INVOICE_DOC).

here is wdDoInit() method of my view controller..

public void wdDoInit()

{

IWDAttributeInfo attInfo =

wdThis.wdGetDemurrageCompController().wdGetContext ().nodeSubmitElements().getNodeInfo().getAttribute(IPrivateDemurrageComp.ISubmitElementsElement.INVOICE_DOC);

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

}

Any Idea why I am having this..

I went through some tutorials, The controller node has cardinality of 1..1...

Accepted Solutions (1)

Accepted Solutions (1)

former_member206397
Contributor
0 Kudos

Hi,

Could you please try with the following code. Here I have an Action for file uploading.

public void wdDoInit()

{

//@@begin wdDoInit()

// get attribute info for context attribute "FileResource"

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(

IPrivateFileUploadView.IContextElement.FILE_RESOURCE);

// make the context attribute's simple type modifiable.

// Only with this line of code the binary data (stored within the

// context attribute) can be parsed. The Web Dynpro Runtime stores

// the mime-object’s metadata within the attribute’s type metadata.

attributeInfo.getModifiableSimpleType();

// set the file details invisible

wdContext.currentContextElement().setDetailsVisibility(

WDVisibility.NONE);

//@@end

}

//Another method for File upload button

public void onActionUploadFile(

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

//@@begin onActionUploadFile(ServerEvent)

// get attribute info for context attribute 'FileResource'

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(

IPrivateFileUploadView.IContextElement.FILE_RESOURCE);

// get modifiable binary type from the attribute info,

// requires type cast.

IWDModifiableBinaryType binaryType =

(IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();

IPrivateFileUploadView.IContextElement element =

wdContext.currentContextElement();

// if a file in the 'FileResource' attribute exists

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

try {

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

byte[] file = element.getFileResource();

// get the size of the uploaded file

element.setFileSize(this.getFileSize(file));

// get the extension of the uploaded file

element.setFileExtension(

binaryType.getMimeType().getFileExtension());

// NOTE: context attribute 'FileName' must not be set

// because the FileUpload-UI-element property 'fileName'

// is bound to it. Consequently the fileName is automatically

// written to the context after file upload.

// set the details visibility attribute

element.setDetailsVisibility(WDVisibility.VISIBLE);

// report success message

wdComponentAPI.getMessageManager().reportMessage(

IMessageFileUpDownloadComp.SF_UPLOAD,

new Object[] { binaryType.getFileName()},

false);

} catch (Exception e) {

throw new WDRuntimeException(e);

}

}

// if no file in the 'FileResource' attribute exists

else {

// set the details visibility attribute, hide details

element.setDetailsVisibility(WDVisibility.NONE);

// report error message

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

msgMgr.reportContextAttributeMessage(

element,

attributeInfo,

IMessageFileUpDownloadComp.NO_FILE,

new Object[] { "" },

true);

}

// clear the FileResource context value attribute

element.setFileResource(null);

//@@end

}

Thanks

Chandan

Answers (3)

Answers (3)

Former Member
0 Kudos

Well...not using attribute binding now in this case.

Former Member
0 Kudos

Hi Garg,

Please have a look into thiese links.. hope these helps...

<a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2flibrary%2fwebdynpro%2fwdJava%2FWDTutorials%2FUploadingandDownloadingFilesinWebDynpro+Tables.pdf">Uploading and Downloading Files in Web Dynpro Tables</a>

and <a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2flibrary%2fwebdynpro%2fwdJava%2FUploadfileusingWebServiceinWebDynproJava+Application.pdf">Upload file using Web Service in Web Dynpro Java Application</a>

Hope these helps...

Please reward points if it helps..

Thanks and Regards

Avijit

Former Member
0 Kudos

No ...two things I wanna mention here...

1- I am using Netweaver04...not 04S

2- when I dont use an attribute mapped to compController attribute..it works...

But when I use mapped attribute it gives me <i>< Parse method is not possible for this type ></i>

Thanks

Former Member
0 Kudos

That does not help