0

I am having a problem displaying graphic image. I want to make images selectable with checkbox. Image path is withdrawed from database. Here is a code of display:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://xmlns.jcp.org/jsf/html"
            xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
            xmlns:p="http://primefaces.org/ui"
            xmlns:f="http://xmlns.jcp.org/jsf/core">
<p:outputPanel autoUpdate="true" rendered="#{loggedUser.isLogged() == true}">
    <h:head>
    </h:head>
    <h:form>
        <p:growl autoUpdate="true" sticky="true" id="growl" showDetail="true" />
        <ui:repeat value="#{orderMB.photoList}" var="photo">
            <p:selectBooleanCheckbox value="#{orderMB.selection[photo]}" />
            <p:graphicImage value="#{photo.toStreamedContent()}"/>
        </ui:repeat>
    </h:form>
</p:outputPanel>

Here is a OrderMB:

public class UserOrderMB {

@Inject
LoggedUser loggedUser;

private List<Photo> photoList;

private Map<Photo, Boolean> selection;

@PostConstruct
public void init() {
    photoList = loggedUser.getPhotoList();
    selection = new HashMap<>(); // No need to prefill it!
}

public List<Photo> getPhotoList() {
    return photoList;
}

public void setPhotoList(List<Photo> photoList) {
    this.photoList = photoList;
}

public LoggedUser getLoggedUser() {
    return loggedUser;
}

public void setLoggedUser(LoggedUser loggedUser) {
    this.loggedUser = loggedUser;
}


public Map<Photo, Boolean> getSelection() {
    return selection;
}

public void setSelection(Map<Photo, Boolean> selection) {
    this.selection = selection;
}

}

And a code that changed photo to StreamedContent:

   public StreamedContent toStreamedContent(){
    StreamedContent sc = new DefaultStreamedContent();
   try {
      sc  = new DefaultStreamedContent(new FileInputStream(new File(getPhotoPath())), "image/png");
   }
   catch (FileNotFoundException e){
       e.printStackTrace();
   }
   return sc;
}

I am sure that photoList has the content and that photos are acctualy changed and they are in good location. The site just displays the checkboxes without images. It is not a duplicate since I don't hold images in database but on drive. I keep only path to image on database.

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
Dreik
  • 140
  • 2
  • 2
  • 11
  • There are a lot of 'Related' links on the right (if you use the desktop pages of StackOverflow). Please read them and see if it provides information to your problem (I think it does) – Kukeltje Jun 06 '17 at 18:26
  • I've read like all of them. Tried to add path to server (I'm using wildfly), tried to get it from servlet. Well I tried all of them I think. That is why I ask in my own question, – Dreik Jun 06 '17 at 18:54
  • Possible duplicate of [Display dynamic image from database with p:graphicImage and StreamedContent](https://stackoverflow.com/questions/8207325/display-dynamic-image-from-database-with-pgraphicimage-and-streamedcontent) – Kukeltje Jun 06 '17 at 20:05
  • Before you call duplicate please read carefully – Dreik Jun 06 '17 at 20:22
  • I did... that is why I think it is a duplicate. If you think I am wrong (which I cannot exclude), please state why it is not a duplicate. Just the fact that you use a file instead of a database does not make a difference when the streamed content is used (afaik) – Kukeltje Jun 06 '17 at 20:25
  • But please read carefully... the answer in this case, since after re-reading both again (this question and 'duplicate' answer) I do think it is a 100% duplicate – Kukeltje Jun 06 '17 at 20:41
  • What is the value of `#{photo.toStreamedContent()}` ? sorry what is the content of `getPhotoPath()` ? – Jorge Campos Jun 06 '17 at 20:43
  • It is not a duplicate becasue I'm getting File from drive not database and these are completely 2 different operations. If I would pick image from database I would be sure that persistance contex will serve me the object but while I use file that file is not available for some reason, thats what I assume after I checked that I'm stating correct path to file – Dreik Jun 06 '17 at 21:29
  • `getPhotoPath() ` content is for example C:/images/user/photoname. As for `#{photo.toStreamedContent()}` is conversion of Photo toStreamedContent and that is an object that should be served to graphicImage. – Dreik Jun 06 '17 at 21:41

0 Answers0