• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

rendering in a PhaseListener

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
He does not suffer fools gladly. But this tiny ad does:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic