【问题标题】:Load image from inside a project folder and Display in jsf popup从项目文件夹中加载图像并在 jsf 弹出窗口中显示
【发布时间】:2016-02-21 17:13:09
【问题描述】:

在我的要求中,我的项目文件夹中有一个图像,如果数据库不包含图像,我会在弹出窗口中显示默认图像

默认图像不显示其显示为空

数据库图像的一切工作正常

点击PDF按钮后,它执行以下方法:

public void getImage(ExpenseTO to) {
        ExpenseTO fetchEntityById = accountService.fetchEntityById(
                ExpenseTO.class, to.getExpenseId());
        byte[] fileScanned = fetchEntityById.getUploadedScanedFile();
        if (fileScanned.length <= 20) {
            try {
                ClassLoader classLoader = Thread.currentThread()
                        .getContextClassLoader();
                InputStream input = classLoader.getResourceAsStream("file.png");
                byte[] bytes = IOUtils.toByteArray(input);
                outPutPdfToDisplay = new DefaultStreamedContent(
                        new ByteArrayInputStream(bytes));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            outPutPdfToDisplay = new DefaultStreamedContent(
                    new ByteArrayInputStream(fileScanned));
        }
    }

它执行时没有任何异常但不显示
弹出窗口中的图像

【问题讨论】:

    标签: java bytearray inputstream


    【解决方案1】:

    我终于找到了解决办法

    在 JSF 的帮助下

    听到我的代码:

    public void getImage(ExpenseTO to) {
            ExpenseTO fetchEntityById = accountService.fetchEntityById(
                    ExpenseTO.class, to.getExpenseId());
            byte[] fileScanned = fetchEntityById.getUploadedScanedFile();
            if (fileScanned.length <= 20) {                     
                    outPutPdfToDisplay=null;            
            } else {
                outPutPdfToDisplay = new DefaultStreamedContent(
                        new ByteArrayInputStream(fileScanned));
                }
        }  
    

    对话框是:

    <p:dialog widgetVar="test" id="dialog" position="300,10"  draggable="true"  modal="true" resizable="false" closable="true">
                        <p:media rendered="#{accountsHomeBean.outPutPdfToDisplay != null}" value="#{accountsHomeBean.outPutPdfToDisplay}" width="700px" height="700px" player="pdf" cache="false" />
                        <h:graphicImage value="/images/file.png"   rendered="#{accountsHomeBean.outPutPdfToDisplay == null}"/>
                    </p:dialog>
    

    如果图像存在于数据库中,&lt;p:media&gt; 标签被执行 否则如果图像在数据库中为空,它将执行&lt;h:graphicImages&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-11
      • 2021-11-01
      • 2022-10-04
      • 1970-01-01
      • 2012-04-17
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多