显示图形图像时遇到问题。我想用复选框选择图像。图像路径从数据库中撤消。这是一个显示代码:
<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>
这是一个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;
}
}
将照片更改为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;
}
我确信photoList有内容,并且照片会被更改,并且位置很好。该网站只显示没有图像的复选框。 这不是重复,因为我不在数据库中但在驱动器上保存图像。我只保留数据库中的图像路径。