Hi,
i tried to implement a renderer with the PhaseListener.
The sandbox tag doesn't work for me. I don't know why, but an image wouldn't be
rendered.
I think that is a problem with facelets and the sandbox tags.
I implemented all properly what i've found in the wikis, but it doesn't work
for me.
So a Listener is my last hope...
The Listener works fine, but the image will not be rendered.
The problem is, that the hex-string is appended on the end of the UIViewRoot.
Have you any ideas what i am doing wrong?
It would be very, very , very nice.
My Tag:
<h:graphicImage src="imagephaselistener" />
My Listener:
public class ImagePhaseListener implements PhaseListener {
private static final Logger log = Logger
.getLogger(ImagePhaseListener.class);
public void setPhase(String newValue) {
}
public PhaseId getPhaseId() {
return PhaseId.UPDATE_MODEL_VALUES;
}
public void beforePhase(PhaseEvent e) {
log.info("BEFORE " + e.getPhaseId());
}
public void afterPhase(PhaseEvent e) {
log.info("AFTER " + e.getPhaseId());
FacesContext context = null;
log.info("!Image will be rendered!!!");
byte[] bytes = "FFD8FFE000104A"
.getBytes();
context = e.getFacesContext();
HttpServletResponse response = (HttpServletResponse) context
.getExternalContext().getResponse();
response.setContentType("image/jpeg");
response.setContentLength(bytes.length);
ServletOutputStream out = null;
try {
out = response.getOutputStream();
} catch (IOException e2) {
log.error("Error at stream creation " + e2);
e2.printStackTrace();
}
try {
out.write(bytes, 0, bytes.length);
} catch (IOException e1) {
log.error("Error at image creation " + e1);
e1.printStackTrace();
}
context.responseComplete();
}
}