3 回答

慕尼黑的夜晚無繁華
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個贊
<h:graphicImage>
<img>
<Context path="/myapp" aliases="/images=/path/to/external/images"></Context>
<h:graphicImage
<img>
<h:graphicImage value="/images/my-image.png">
<img src="/myapp/images/my-image.png">
<p:fileDownload>
<h:form> <h:commandLink id="downloadLink" value="Download"> <p:fileDownload value="#{fileDownloader.getStream(file.path)}" /> </h:commandLink></h:form
@ManagedBean@ApplicationScopepublic class FileDownloader { public StreamedContent getStream(String absPath) throws Exception { FileInputStream fis = new FileInputStream(absPath); BufferedInputStream bis = new BufferedInputStream(fis); StreamedContent content = new DefaultStreamedContent(bis); return content; } }}

阿晨1998
TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個贊
private StreamedContent image;public void setImage(StreamedContent image) { this.image = image;}public StreamedContent getImage() throws Exception { return image;}public void prepImage() throws Exception {File file = new File("/path/to/your/image.png"); InputStream input = new FileInputStream(file);ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); setImage(new DefaultStreamedContent(input,externalContext.getMimeType(file.getName()), file.getName()));}
<body onload="#{yourBean.prepImage()}"></body> <p:graphicImage value="#{youyBean.image}" style="width:100%;height:100%" cache="false" > </p:graphicImage>
添加回答
舉報
0/150
提交
取消