I tried to use the same code of Dynamic Image in the showcase to the Liferay portlet.
But no image can be displayed.
Code: Select all
Primefaces 3.0
Portletfaces-portletbridge-2.0.1
Liferay 6.0.6
Java 6
Code: Select all
<p:graphicImage value="#{imageController.graphicText}" cache="false"/>
Code: Select all
@ManagedBean(name="imageController")
@RequestScoped
public class ImageStreamController {
private StreamedContent graphicText;
public ImageStreamController() {
try {
BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bufferedImg.createGraphics();
g2.drawString("This is a text", 0, 10);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImg, "jpg", os);
graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/jpeg");
} catch(Exception e) {
e.printStackTrace();
}
}
public StreamedContent getGraphicText() {
System.out.println("...........YEAH");
return graphicText;
}
public void setGraphicText(StreamedContent graphicText) {
this.graphicText = graphicText;
}
}