Load images from local Disk (Server)

UI Components for JSF
Post Reply
Cybernout
Posts: 6
Joined: 29 Jan 2013, 16:23

19 Nov 2017, 19:53

Hi community,
i try to load images from outside the container. I can`t find a solution. Here is my simple code. It's reduced. I want to do it in a dynamic dashboard and in one getter method. But this is not yet my question. So i tried it with 3 getter functions. With static png files all works fine. But i don't know what happened when i load the files from outside. I've tried so much but the result is always different. Once the getter methods are each loaded on time, in another try one getter methods is loaded twice time in differnt phases. but then nothing is shown. In the other case the pictures are loades, but when i change one png file or more, always the old are shown, nothing change. I deleted the cache, nothing change, every time the old pictures, when they are loaded, in most cases they are not loaded.
The bean is not from me and there was said that the getter method is loaded twice with differnt phases but this seems not correct. I have three images and for every graphicimage the getters is loaded once with PhaseId.RENDER_RESPONSE. If one getter method is loaded twice (every time only one and different) with another Phaseid nothing is shown and this happens completely arbitrary, and on the other side, how i said, the image are loaded and i change one, load the app again, nothing is changed. The old files are shown. I dont know why and when. You see there are so much problems. Has anyone a solution that works?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">

<h:head>

<f:facet name="first">
<title>Titel</title>
</f:facet>
</h:head>

<h:body>
<h:form id="Haupt">
<p:column>
<p:graphicImage value="#{loadImageFile.image1}">
</p:graphicImage>
</p:column>
<p:column>
<p:graphicImage value="#{loadImageFile.image2}">
</p:graphicImage>
</p:column>
<p:column>
<p:graphicImage value="#{loadImageFile.image3}">
</p:graphicImage>
</p:column>
</h:form>
</h:body>
</html>

Backing Bean (SessionScoped, with RequestScope the same): there are 3 getter methods but the same structure

public StreamedContent getImage1() {
FacesContext context = FacesContext.getCurrentInstance();

if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
try {
imageEinAus1 = new DefaultStreamedContent();
} catch (IOException ex) {
Logger.getLogger(LoadImageFile.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
try {
Path path = Paths.get("C:\\ESD\\LightOff.png");
byte[] data = Files.readAllBytes(path);
imageEinAus1 = new DefaultStreamedContent(new ByteArrayInputStream(data), "image/png", "LightOff.png");
} catch (IOException ex) {
Logger.getLogger(LoadImageFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
return (imageEinAus1);
}

Glassfish 5, Primefaces 6.1
primefaces 3.5/server faces 2.1
netbeans 7.2.1/glassfish 3.2.1
windows 7 home

Cybernout
Posts: 6
Joined: 29 Jan 2013, 16:23

19 Nov 2017, 20:29

Ok, found cache must be false, then iamges are refreshed
primefaces 3.5/server faces 2.1
netbeans 7.2.1/glassfish 3.2.1
windows 7 home

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: imrankhurram and 64 guests