cancel
Showing results for 
Search instead for 
Did you mean: 

auto update of image

0 Kudos

Heya

I'm about to have a first go on UI5 and what I'm trying to do sounds rather simple to me - yet I haven't succeedet yet. Maybe someone of the comunity my be able to point me in the right direction?

My situation: I have a URL that points to my image. The URL stays the same, just the image is constantly repainted. I would like to update this new image in my view.

What I did do is the following:

I created a view and a model. The model contains the URL to the image

var dataObject = {
            "src" : "http://myurl.com/current.jpg",
        };
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(dataObject);
sap.ui.getCore().setModel(oModel);

Then I bound this model to an image:

var myImage = new sap.m.Image("i1");

  myImage.setSrc(oModel.getProperty('/src'));

Then I've added this image to a page and display this page in my app.

var page = new sap.m.Page({
title: "image",
content:  myImage,
});

The result is, that the app shows the very first image but will never update the content.

How would I trigger the repeating update of this image?

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member182862
Active Contributor
0 Kudos

HI Bernd

The image control is unable to know that the image that is referenced by the URL is changed. So you need a timer to refresh the model with a different URL to notify the image to render. You can add some random string to the URL to make the URL different from the previous one. e.g.

http://myurl.com/current.jpg?a=<uuid>;

and this will also avoid browser caching your image.

Here is an example with icon.

-D

jmoors
Active Contributor
0 Kudos

If the URL doesn't change I think you will run into browser caching issues.

Many thanks,

Jason

0 Kudos

Hi Jason

I believe this should not be an issue. If I auto reload the whole page, I keep getting an updated image( e.g via <meta http-equiv="refresh" content="1" >)

But this is not a clean way to solve the issue and I keep looking for a solution that just updates the image object.