cancel
Showing results for 
Search instead for 
Did you mean: 

Not getting Image

Former Member
0 Kudos

Hi

I have done the tabstip example... i have created two Tabs

EDIT and DISPLAY.... its working fine... but image is not working.... i am uploading the image file in EDIT VIEW when i click save button it has to display in DISPLAY VIEW... but when i click save i am getting

<b>"NULL POINTER EXCEPTION"</b>

i have wrrinten the following code in "onActionSave()"

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

{

//@@begin onActionSave(ServerEvent)

/* System.out.println("Ravi");*/

wdThis.wdGetUIComponentController().preparationForFileDownload();

IPrivateEditMyDataView.IMyDataElement myDataElement = wdContext.currentMyDataElement();

if (myDataElement != null) {

myDataElement.setFile(myDataElement.getPicture());

}

//$$end

//image source change

if(wdContext.currentMyDataElement().getPictureName() == null){

wdContext.currentImageElement().setDefault(false);

}

else{

wdContext.currentImageElement().setDefault(true);

}

//@@end

}

<b>preparationForFileDownload();this method i have implemented in UIComponent class

</b>public void PreparationForFileDownload( )

{

//@@begin PreparationForFileDownload()

IWDAttributeInfo attInfo = wdContext.nodeMyData().getNodeInfo().getAttribute("File");

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

//in addition the FileDownload UI element needs for defined resource types

binaryType.setFileName(wdContext.currentMyDataElement().getAttributeAsText("PictureName"));

binaryType.setMimeType(WDWebResourceType.JPG_IMAGE);

//@@end

}

I am getting error on the following line

wdContext.currentImageElement().setDefault(true); in

onActionSave() method of EditView....

Please Help Me....

Thanks & Regards

Ravi Shankar B

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Ravi,

Check The Cardinality of the node Image and set cardinality is 1..1 of 0..1

Kind Regards

Mukesh.

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

I think ur using file download,

Follow the steps:

1)Put ur images in src>mimies>compoments.

create an attribute fileresource and declare the

image as FILE_NAME =image.JPEG globally

2)write the code in meathod() or action

[code]IWDAttributeInfo attributeInfo =wdContext.getNodeInfo().getAttribute(IPrivateFiledownloadappView.IContextElement.FILERESOURCE);
 binaryType =(IWDModifiableBinaryType)attributeInfo.getModifiableSimpleType()binaryType.getFileName();

try {
	
	String resourcePath =
	WDURLGenerator.getResourcePath(
	wdComponentAPI.getDeployableObjectPart(),
	FiledownloadappView.FILE_NAME);
	
 wdContext.currentContextElement().setFileresource(
 this.getByteArrayFromResourcePath(resourcePath));

 binaryType.setFileName(FiledownloadappView.FILE_NAME);
 binaryType.setMimeType(WDWebResourceType.JPEG);
} catch (WDAliasResolvingException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} catch (FileNotFoundException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

3)write the getByteArrayFromResourcePath method code in

//@@begin others

 private byte[] getByteArrayFromResourcePath(String resourcePath)
  throws FileNotFoundException, IOException {
  FileInputStream in = new FileInputStream(new File(resourcePath));
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int len;
  byte[] part = new byte[10 * 1024];
  while ((len = in.read(part)) != -1) {
  out.write(part, 0, len);
  }
  in.close();
  return out.toByteArray();
  }
//store image file name in constant FILE_NAME
IWDModifiableBinaryType binaryType ;
private static final String FILE_NAME = "image.JPEG";
		

//@@end

Regards,

Vijayakhanna Raman