[英]Show one imagem using graphicImage
我試圖顯示一張可以存儲在一個文件夾中的內存中的圖像,第一個嘗試顯示文件夾中的內容...
我正在調用帶有commandbutton
dialog
,並且在dialog
內部有一個graphicImage
但是它沒有顯示圖像。
那怎么了
<p:dialog header="#{lbl['LABEL.ATENDENTE.IMAGEMCERTIFICADO']}" widgetVar="dlgViewCpfImagem" modal="true" resizable="false" closable="false" dynamic="true">
<h:form id="formDlgViewCpfImagem" enctype="multipart/form-data">
<p:messages id="messageDlgViewCpfImagem" showDetail="true"/>
<p:panelGrid styleClass="noBorders panelGridCenter gridNoBackground">
<p:row>
<p:column>
<p:graphicImage value="#{atendenteBean.fileCpf.getAbsolutePath()}"/>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
<center>
<p:commandButton process="@this" value="#{lbl['BOTAO.FECHAR']}" oncomplete="dlgViewCpfImagem.hide()" update=":form:panelAnexarArquivo"/>
</center>
</p:dialog>
<p:column rendered="#{not empty atendenteBean.pojo.imgCpf}">
<p:commandButton process="@this" icon="botaoLog" styleClass="botaoImagem" oncomplete="dlgViewCpfImagem.show()"/>
</p:column>
似乎您試圖顯示一個文件指向文件系統中存儲的文件。 除非您使用動態圖像流,否則這將無法工作。 請參閱以下示例:
托管豆
import java.io.File;
import java.io.InputStream;
import javax.faces.bean.SessionScoped;
import org.apache.commons.io.FileUtils;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
@ManagedBean
@SessionScoped
public class DynamicImageController {
private StreamedContent graphicImage;
public DynamicImageController() {
try {
//The image file you want to show
File file = new File("d:\\image.png");
InputStream is = FileUtils.openInputStream(file);
graphicImage = new DefaultStreamedContent(is, "image/png");
} catch (Exception e) {
e.printStackTrace();
}
}
public StreamedContent getGraphicImage() {
return graphicImage;
}
}
PS:我使用會話范圍的bean,因為我希望它很簡單。 您應該考慮一種更復雜的機制,以避免在會話中存儲太多數據。 請記住,image標簽使用不同的http連接,ViewScoped bean可能不是一個好的選擇。
風景
<p:graphicImage value="#{dynamicImageController.graphicImage}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.