从项目Primefaces外部的字符串路径显示图像

时间:2017-10-04 04:36:36

标签: image jsf primefaces graphicimage

我有用于在标题上显示图像的String路径,我从数据库中获取返回图像的String文件名的路径,然后图像位于“D:\ Job \ Potapota \ images \(filename) ”。我已经从db初始化了a.setValue(dao.getLogos());中的String路径。这意味着我是否只想获得文件名,如a.getValue()。

所以这是我的html页面

<p:graphicImage value="#{fileUploadViewBean.imageStatus}" library="atlantis-layout"/>

然后类FileUploadViewBean就是这个

public class FileUploadViewBean extends CommonBean {

private StreamedContent imageStatus;
public void init() throws IOException{
    getLogo();
}

public StreamedContent getImageStatus() {
    return imageStatus;
}

public void setImageStatus(StreamedContent imageStatus) {
    this.imageStatus = imageStatus;
}

public void getLogo() throws IOException {
    SystemMaster a = new SystemMaster();
    FacesContext context = FacesContext.getCurrentInstance();
    try {
        a.setValue(dao.getLogos());
    } catch (Exception e) {
        setMessage(new FacesMessage(e.getMessage()));
        getMessage().setSeverity(FacesMessage.SEVERITY_FATAL);
        FacesContext.getCurrentInstance().addMessage(null, getMessage());
    }
    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        // So, we're rendering the view. Return a stub StreamedContent so
        // that it will generate right URL.
        imageStatus = new DefaultStreamedContent();
    } else {
        // So, browser is requesting the image. Return a real
        // StreamedContent with the image bytes.
        String filename = 
context.getExternalContext().getRequestParameterMap().get(a.getValue());
        imageStatus = new DefaultStreamedContent(
                new FileInputStream(new File("D:\\Job\\Potapota\\images\\", 
        filename)), "image/jpeg");
    }
}

但是图像没有显示出来,有人知道这是什么真正的代码。

0 个答案:

没有答案