从项目文件夹中加载图像并在 jsf 弹出窗口中显示
Load image from inside a project folder and Display in jsf popup
根据我的要求,我的项目文件夹中有一个图像,如果数据库不包含图像,我会在弹出窗口中显示默认图像
默认图像不显示它显示空
数据库图像一切正常
单击 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));
}
}
它执行没有任何异常但不是不显示
弹出窗口中的图片
终于找到了解决方案
借助 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>
如果图像存在于数据库中 <p:media>
标签被执行
否则,如果图像在数据库中为空,它将执行 <h:graphicImages>
根据我的要求,我的项目文件夹中有一个图像,如果数据库不包含图像,我会在弹出窗口中显示默认图像
默认图像不显示它显示空
数据库图像一切正常
单击 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));
}
}
它执行没有任何异常但不是不显示
弹出窗口中的图片
终于找到了解决方案
借助 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>
如果图像存在于数据库中 <p:media>
标签被执行
否则,如果图像在数据库中为空,它将执行 <h:graphicImages>