本文介绍了如何正确使用a4j:mediaOutput来显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码,我无法在网页中获取图像.我不确定我是否以正确的方式理解了文档,并且找不到与此代码有关的任何问题.

Using the code below I can't get the image in the web page. I'm not sure if I understand the documentation in the right way and I'm not able to find any problem with this code.

BEAN

@ManagedBean(name = "imageBean")
@RequestScoped
public class ImageBean {
    public void paint(OutputStream os, Object data) throws IOException {
        BinaryContent content = (BinaryContent) data;
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(content.getContent()));
        ImageIO.write(image, "jpg", os);
    }
}

PAGE

<rich:dataTable value="#{dataProviderBean.aoRequests}" var="item">
    <f:facet name="noData">No messages are available.</f:facet>
    ...
    <rich:column>
        <f:facet name="header">Image data</f:facet>
        <rich:list value="#{item.imageContents}" var="content">
            <a4j:mediaOutput element="img" cacheable="false" session="false"
                createContent="#{imageBean.paint}" value="#{content}" />
        </rich:list>
    </rich:column>
</rich:dataTable>

推荐答案

如果将来有人遇到相同的问题,请使用以下解决方案:

If someone will have the same problem in the future, here is the solution:

我放入value属性的content是一个保存图像二进制数据的对象.由于它是在URL中序列化的,因此长度太大,因此无法正常工作.您必须传递一些id并通过paint方法获取对象.

The content I put into value attribute is an object which holds binary data of a image. Because it is serialized in URL, the length is too big and it does not work. You have to pass some id and fetch the object in the paint method.

Example

<rich:dataTable value="#{dataProviderBean.aoRequests}" var="item">
    <f:facet name="noData">No messages are available.</f:facet>
    ...
    <rich:column>
        <f:facet name="header">Image data</f:facet>
        <rich:list value="#{item.imageContents}" var="content">
            <a4j:mediaOutput element="img" cacheable="false" session="false"
                createContent="#{imageBean.paint}" value="#{content.id}" />
        </rich:list>
    </rich:column>
</rich:dataTable>

BEAN

public void paint(OutputStream os, Object data) throws IOException {
    String id = (String) data;
    BinaryContent content = (BinaryContent) getContentById(id);
    os.write(content.getContent());
}

这篇关于如何正确使用a4j:mediaOutput来显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:13