cancel
Showing results for 
Search instead for 
Did you mean: 

FileUpload and Image

Former Member
0 Kudos

Hi ,

Can u briefly explain me about the FileUpload and FileDownload Image UIElement . Actually i want to put FileUpload in One Tab of tabstrip and Give Image UIElement in other tab of the TabStrip. So that when i Press second tab it should Display the content in the Image UIElement which is in transparentContainer of the Second tab. Is it possible to do like that.?

If possible can u tell me.

And what r the data property and resource property of FileUpload.

What code i have to write. I searched in full sdn but I dint get the concept behind it.

**For that i got reply from sdn, like this.**

You mean to say that you want to display the uploaded image in the Image UI when you go to the next tab. This you can achieve without using the file download UI as well.

You can write the following code in the tab change action for the second Tab ID:

IWDResource cache = WDResourceFactory.createCachedResource(wdContext.node<Node Name>().current<Node Name>Element().getEmpImage(),fileName,WDWebResourceType.JPG_IMAGE);

// Here EmpImage is the attribute of type byte array(byte []) i.e the uploaded content, filename is any String of your choice.

wdContext.nodeImage().currentImageElement().setImageSrc(cache.getUrl(0));

// Here ImageSrc is the attribute mapped to the src property of the Image UI.

So i tried this to in the example application, but i am getting error like this.

The method createCachedResource(InputStream, String, WDWebResourceType, boolean) in the type WDResourceFactory is not applicable for the arguments (byte, String, WDWebResourceType)

This is the code which i wrote.

IWDResource resource= wdContext.currentMyDataElement().getImgSource();

byte by=wdContext.nodeMyData().currentMyDataElement().getPicture();

String str = wdContext.nodeMyData().currentMyDataElement().getFile();

IWDResource cache = WDResourceFactory.createCachedResource(

by,str,WDWebResourceType.JPG_IMAGE);

Can u please Explain this to me. If any other way to do it ,then please explain me.

Regards,

H.V.Swathi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

It should be byte [] and not byte. I mean to say that make the attribute "Picture of type binary". Select the type binary in the type dropdown for the attribute Picture.

Are you saving the picture uploaded in the backend? And how you are getting it back from the backend?

thanks & regards,

Manoj

Former Member
0 Kudos

Thanks,

I wrote this code.

IWDResource resource= wdContext.currentMyDataElement().getImgSource();

byte[] by=wdContext.nodeMyData().currentMyDataElement().getPicture();

String str = wdContext.nodeMyData().currentMyDataElement().getFile();

IWDResource cache = WDResourceFactory.createCachedResource(

by,str,WDWebResourceType.JPG_IMAGE);

wdContext.nodeMyData().currentMyDataElement().setImgSource(cache.getUrl(0));

But i am getting error like this.

The method setImgSource(IWDResource) in the type IPrivateDisplayMyDataView.IMyDataElement is not applicable for the arguments (String)

Please tell me what might be the problem. i am not storing it anyware but i want to see that image only in next tab by taking url, which i specified in upload UIelement which is in first tab.so i thought, i will use context element.

Regards,

H.V.Swathi

Former Member
0 Kudos

Hi,

Did you check if it is possible to type cast string into IWDResource ..i.e, using the method as setImgSource((IWDResource)cache.getUrl()) ?

Rgds,

Anagha

Former Member
0 Kudos

ye i tried it. That type casting is not possible..

What can u istead of this.

Regards,

H.V.Swathi

Former Member
0 Kudos

Hi,

Try giving cache, instead of cache.getUrl(0)?

just a guess...

Rgds,

Anagha

Former Member
0 Kudos

Yes..

that error is not there but while running the application i am getting this error.

The initial exception that caused the request to fail, was:

java.lang.NullPointerException

at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89)

at com.sap.tc.webdynpro.progmodel.mime.CachedResource.<init>(CachedResource.java:33)

at com.sap.tc.webdynpro.progmodel.mime.ResourceFactory.createCachedResource(ResourceFactory.java:136)

at com.sap.tc.webdynpro.progmodel.api.WDResourceFactory.createCachedResource(WDResourceFactory.java:45)

at com.sap.tutwd_ui_init.DisplayMyDataView.wdDoModifyView(DisplayMyDataView.java:145)

... 31 more

See full exception chain for details.

Regards,

H.V.Swathi

Former Member
0 Kudos

Have you mapped ImageSrc attribute to the src property of the Image UI? Could you paste the code lines where the error is coming?

Former Member
0 Kudos

I am not able to map that context to the image element source property.

ImgSource is of type

com.sap.ide.webdynpro.uielementdefinitions.Resource

What can i do now

Regards,

H.V.Swathi

former_member192434
Active Contributor
0 Kudos

Hi Swati,

Right Click on Attribut>Property>Type(Select Dictonary)->>Local Dictonary>Expand it >com.sap.ide.webdynpro.uielementdefinitions->Expand--->Resource.

Thanks

Former Member
0 Kudos

Hi,

The type of the attribute should be changed accordingly so that you are able to map it to the image UI property.

Refer the above post for how to do it.

Rgds,

Anagha

Former Member
0 Kudos

As i said i have set the type of the attrubute to

com.sap.ide.webdynpro.uielementdefinitions.Resource

But even then i am not able to map UIElement image source property to ImgSourece atribute

Regards,

H.V.Swathi

Former Member
0 Kudos

Hi H.V. Swathi,

Looks like the Image source property can be bound only to a context attribute of type string.

Can you please try by making 'ImgSource' attribute as String and use the same code line as below:

wdContext.nodeMyData().currentMyDataElement().setImgSource(cache.getUrl(0));

Revert if the problem persists,

Anagha

Former Member
0 Kudos

Hi,

Also note, there is an 'alt' property, for which a value is mandatory. You can simply hard code it with an alternative text for e.g "Not Available". It will be displayed when the graphic cannot be opened or found.

Check this link for clarity on properties of Image UI:

http://help.sap.com/saphelp_nw04/Helpdata/EN/f3/1a61a9dc7f2e4199458e964e76b4ba/frameset.htm

Hope it helps.

Rgds,

Anagha

Edited by: Anagha Jawalekar on Nov 12, 2008 10:11 AM

Former Member
0 Kudos

wdContext.nodeMyData().currentMyDataElement().setImgSource(cache.getUrl(0));

will give error becouse setImgSource is of type setImgSource(IWDResource).

So we cant do that..

Is there any other way to do it.

Regards,

Swathi

Former Member
0 Kudos

As suggested, can you first change the type of attribute ImgSource to string and then use the below line of code?

wdContext.nodeMyData().currentMyDataElement().setImgSource(cache.getUrl(0));

After that, In case cache.getUrl(0) is not returning string can you try with -

wdContext.nodeMyData().currentMyDataElement().setImgSource(cache.getUrl(0).to String()) ?

Former Member
0 Kudos

Thanks For helping. But i solved that by my self.

I Put these lines of code in the wdDoModifyView method

if (firstTime) {

IWDButton but = (IWDButton) view.getElement("Button_save");

but.mappingOfOnAction().addSourceMapping("nodeElement", "mydataElement");

}

I specified the SupplyFunction in context value node.

And in save button action specified these line of code

if (wdContext.currentMyDataElement().getImgSource() != null) {

// copy URL string from IWDResource object to

// context attribute 'UploadImgURL'. Image gets

// visible on the UI based on databinding definition.

wdContext.currentMyDataElement().setFile(

wdContext.currentMyDataElement().getImgSource().getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));

}

Regards

Swathi

Answers (0)