如何正确使用a4j:mediaOutput来显示图像?
使用下面的代码我无法在网页中获取图像。 我不确定我是否以正确的方式理解文档,并且我无法找到此代码的任何问题。
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
No messages are available. ... Image data
如果将来有人会遇到同样的问题,这是解决方案:
我放入value
属性的content
是保存图像的二进制数据的对象。 因为它是在URL中序列化的,所以长度太大而且不起作用。 你必须传递一些id
并在paint方法中获取对象。
Example
No messages are available. ... Image data
BEAN
public void paint(OutputStream os, Object data) throws IOException { String id = (String) data; BinaryContent content = (BinaryContent) getContentById(id); os.write(content.getContent()); }
ImageBean使用@SessionScoped或@ApplicationScope https://community.jboss.org/thread/168523