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.