2013-10-17 30 views
0

我正嘗試表明,可以存儲在內存中的一個文件夾中的一個圖像,firts我正嘗試顯示該文件夾的內容一個IMAGEM ...顯示使用graphicImage的

I'm通話一個dialogcommandbutton和在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> 

回答

0

看起來您正在嘗試顯示文件指向它存儲在文件系統中的位置。除非您使用Dynamic Image Streaming,否則這將不起作用。看下面的例子:

Managed Bean的

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}" /> 
+0

但有一個問題,因爲該項目是保存圖像從客戶端系統,所以這將是在服務器的根目錄... 我可以是否將該文件複製到流並處理? –