Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

rendering in a PhaseListener  RSS feed

 
Albewrt Gore
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to output something in the HTML document, from a render PhaseListener.
This is part of my code:

public class AjaxRendererPhaseListener implements PhaseListener {

private void addBookmark(UIComponent component) throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", component);
writer.writeAttribute("id", component.getClientId(context), null);
writer.endElement("div");
writer.flush();
}


public void afterPhase(PhaseEvent event) {
UIViewRoot root = event.getFacesContext().getViewRoot();
for(Iterator it = root.getChildren().iterator(); it.hasNext() {
UIComponent component = (UIComponent)it.next();
try {
...
addBookmark(UIComponent component);

} catch (IOException ex) {
ex.printStackTrace();
}
}
}

public void beforePhase(PhaseEvent event) {
}

public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
}

I registered it and I am sure the listener execute the code (I tried with logging).
So why the writer doesn't output anything in the HTML document?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!