cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying Image dynamically.

Former Member
0 Kudos

Hi All,

My requirement is to display image of employees based on the employee ID at runtime. For this i am getting byte[] of the image from the web-service.

And for this i am creating a image.gif file at the folder <ProjectFolder>/src/mimes/Components/<ComponentPackageName

> every time on the lead-select of the employee list. But the image is not getting displayed.

Is there any other way to display an image which is stored in the database.

thanks & regards,

Manoj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

https://help.sap.com/javadocs/NW04S/current/wd/com/sap/tc/webdynpro/progmodel/api/WDResourceFactory....

Using this method, create a web resource, use its URL as the image source.

Armin

Former Member
0 Kudos

Hi Armin,

Its looking very useful. But i really don't know how to use it.

Could you please give me a detailed coding help if possible.

My requirement is as follows:

I am storing the images as blob in DB. I am getting the image content as byte[] from web-service. I have to display the images based on the employee Id at run-time.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi Armin,

Thanks for the helpful link. Now the images are getting displayed.

Best regards,

Manoj

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi

This may help you

Regards

Abhijith YS

Former Member
0 Kudos

Hi

First of all create a separate column in your backend to store the image name along with extension{Suppose imgName}

1. Copy your images into <Project Name>\src\mimes\Components\<your component>\

2. Create a Node Attribute "Image" with cardinality Property as 1..1

2)a Create 2 value attrubutes

i) imageAlt [Calculated Property as TRUE]

ii) imageSource [Calculated Property as TRUE]

now in your NWDS do the following

2)b Bind the imageAlt attribute to ImageUIElement's alt

2)c Bind the imageSource attribute to ImageUIElement's source

tmpImageName=wdContext.CurrentContextElement.getimgName[this statement retrieves the image name from back end

tmpImgaeAlt=wdContext.CurrentContextElement.getEmpName[this statement retrieves the name from back end where in

we use this name as the tooltip for the image]

wdContext.currentImageElement.setImageSource(tmpImageName);

wdContext.currentImageElement.setImageAlt(tmpImgaeAlt);

this will increase db retrival speed.

hope this will solve your purpose..

Best Regards

Abhijith YS

Former Member
0 Kudos

Hi Abhijith,

I am also doing the same way as you told. But as far as copying of images is concerned, i am creating the image file each time according to the employee Id in the folder <Project Name>\src\mimes\Components\<your component>. The code is as follows:

byte[] byteArr;

/LeaveAssessment is a model node and empImage returns image content as byte[]/

byteArr = wdContext.currentLeaveAssessmentElement().getEmpImage();

try{

FileOutputStream createFile = new FileOutputStream("C:
Documents and Settings
manoj.kumar
.dtc
3
DCs
arisglobal.com
ctmlms10
_comp
src
mimes
Components
Image.jpg");

createFile.write(byteArr);

} catch (Exception e){

e.printStackTrace();

}

And the source and alt properties of the image UI Element is also refering to the same file name. But still the image is not getting displayed. One more thing is that i am working on the DC which is in DTR.

Former Member
0 Kudos

Hi

so already you are having some image in your

src\mimes\Components\<your component> right?

now comment the FO code and check whether its working,

i think you are thinking or uploading of new emp images, so you are following uploading images into db,

check this first ,if it works works then we can some way to copy the new image uploaded.

Regards

Abhijith YS

Former Member
0 Kudos

Hi

1. Check whether you are giving extensions like .jpg, .jpeg, .mpeg, if not give that

2. to open a file which is stored in db, we need to know the type of file, so try to store file type also.

Regards

Abhijith YS

SRudra
Contributor
0 Kudos

Manoj,

Do not even attempt to store images into a database, because of performance related issues. It is perfect to keep all images into a folder and load images as needed. Maybe you could keep the path reference of the image into the database field.

As of loading the image, check if the io operation in your code is handled properly.

Cheers!!!

Sukanta Rudra