I’m trying define dynamically the image url in CSS background-image to one Element container like VerticalLayout, HorizontalLayout or Div.
I’m get the StreamResource like this:
StreamResource imageResource = new StreamResource("backgroud.jpg",
() -> getClass().getResourceAsStream("/static/backgrounds/w_"+i+".jpg"));
i is a random integer 1 to 10 interval.
this.getStyle().set("background-image", "url('"+image.getSrc()+"')");
I get back the dynamic image address with one Image component and method getSrc() that return to me one dynamic address. But I can’t access or route Vaadin Application to this address.
Alternativatelly, I’m try access with File too:
File f = new File(getClass().getResource("/static/backgrounds/w_1.jpg").getPath());
this.getStyle().set("background-image", "url('"+f.toURI()+"')");
But I don’t have success in both codes. The CSS return the message that image can’t load.
Any suggestions on how to do it?