我想显示的保存在数据库中的图像字节StreamedContent
中<p:graphicImage>
,如下所示:
<p:graphicImage value="#{item.imageF}" width="50" id="grpImage" height="80"/>
Run Code Online (Sandbox Code Playgroud)
private StreamedContent content; // getter and setter
public StreamedContent getImageF() {
if (student.getImage() != null) {
InputStream is = new ByteArrayInputStream(student.getImage());
System.out.println("Byte :"+student.getImage());
content = new DefaultStreamedContent(is, "", student.getStuID());
System.out.println("ddd ------------------------------- " + content);
return content;
}
return content;
}
Run Code Online (Sandbox Code Playgroud)
这将返回一个空白图像.这是怎么造成的,我该如何解决?
标准输出打印以下内容:
INFO: Byte :[B@a2fb48
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@b0887b
INFO: Byte :[B@a2fb48
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@1d06a92
INFO: Byte :[B@d52f0b
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@39a60
INFO: Byte :[B@d52f0b
INFO: ddd ------------------------------- org.primefaces.model.DefaultStreamedContent@8c3daa …
Run Code Online (Sandbox Code Playgroud) 我在JBoss 7.1.1上使用PrimeFaces 3.2.
我试图在MySQL数据库中显示存储在BLOB中的图像<ui:repeat>
.图像存储在a中byte[]
,然后转换StreamedContent
为如下:
InputStream stream = new ByteArrayInputStream(ingredient.getImage());
ingredient.setJsfImage(new DefaultStreamedContent(stream, "image/jpg"));
Run Code Online (Sandbox Code Playgroud)
然后我试图在Facelet中显示它如下:
<ui:repeat var="ingredient" value="#{formBean.ingredientResultSet}">
<p:panel id="resultsPanel" header="#{ingredient.location.shopName}">
<p:graphicImage value="#{ingredient.jsfImage}" alt="No picture set" />
...
Run Code Online (Sandbox Code Playgroud)
但是,在加载页面时,我在JBoss中收到以下错误:
SEVERE [org.primefaces.application.PrimeResourceHandler](http - 127.0.0.1-8080-12)流式动态资源出错.
这是怎么造成的,我该如何解决?
我想使用PrimeFaces数据表从数据库动态加载图像.代码如下所示,基于此PF论坛主题:
<p:dataTable id="tablaInventario" var="inv" value="#{registrarPedidoController.inventarioList}" paginator="true" rows="10"
selection="#{registrarPedidoController.inventarioSelected}" selectionMode="single"
update="tablaInventario tablaDetalle total totalDesc" dblClickSelect="false" paginatorPosition="bottom">
<p:column sortBy="producto.codigo" filterBy="producto.codigo">
<f:facet name="header">#{msg.codigo}</f:facet>
#{inv.producto.codProducto}
</p:column>
<p:column>
<f:facet name="header">Foto</f:facet>
<p:graphicImage id="photo" value="#{registrarPedidoController.streamedImageById}" cache="FALSE">
<f:param name="inv" value="#{inv.id}" />
</p:graphicImage>
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
同
public StreamedContent getStreamedImageById() {
DefaultStreamedContent image = null;
String get = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("inv");
System.out.println("[Param]: " + get); // This prints null.
Long id = new Long(get);
List<Inventario> listInventarios = controladorRegistrarPedido.listInventarios();
for (Inventario i : listInventarios) {
if (i.getId().compareTo(id) == 0) {
byte[] …
Run Code Online (Sandbox Code Playgroud) 我试图显示一个面板,用户可以看到项目列表类别(显示为图像),点击后可以查看该类别中的产品(图像将显示)
为了显示项目类别,我使用了ui:重复nad支持bean calss下面是我的xhtml代码
<ui:repeat id="repeat" value="#{getData.images}" var="img" varStatus="loop">
<h:panelGroup>
<p:graphicImage id="img1" value="#{img}" alt="image not available" >
</p:graphicImage>
</h:panelGroup>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
和Managed Bean Code部分
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private List<StreamedContent> imageList = new ArrayList<StreamedContent>();
public List<StreamedContent> getImages(){
for (int i = 0; i < sdh.getNumOfImages(); i++) {
imageID = imageIDArray.get(i);
ImageService imgSer = new ImageService();
imgList.add(imageID);
imgSer.setData(imageID);
baos = imgSer.getImage();
try {
imageList.add(new DefaultStreamedContent(new
ByteArrayInputStream(baos.toByteArray())));
} catch (Exception ex) {
ex.printStackTrace();
}
}
imageNum = 0;
return imageList;
}
public …
Run Code Online (Sandbox Code Playgroud) 我在eclipse下收到以下警告:
WARNING: JSF1091: No mime type could be found for file dynamiccontent. To resolve this, add a mime-type mapping to the applications web.xml
Run Code Online (Sandbox Code Playgroud)
发布图片时会导致此错误
在primefaces composant下面:
<p:graphicImage value="#{bean.image}"/>
Run Code Online (Sandbox Code Playgroud)
Java Bean:
private StreamedContent image;
// Getter
public StreamedContent getImage() {
try {
JFreeChart jfreechart = ChartFactory.createPieChart3D("",
createDataset(), true, true, false);
PiePlot3D plot = (PiePlot3D) jfreechart.getPlot();
File chartFile = new File("dynamichart");
ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300);
chartImage = new DefaultStreamedContent(new FileInputStream(
chartFile), "image/png");
return chartImage;
} catch (Exception e) {
e.printStackTrace();
return new …
Run Code Online (Sandbox Code Playgroud)