tags:

views:

29

answers:

1

I want to correct indent before I send a JSF page to the user, because the indent is a little bit messy from JSF and it would be easier to do css stylig with nicier indent. So I want to redirect all output written by JSF rendering to a variable, parse it and then send it to the user. I tried to play a little with and thought that the <f:phaseListener> listening to RenderPhase might be the right way to go, but I don't know how to do that concretely.

+1  A: 

A Filter is the best tool for the job. A PhaseListener is only interesting if you're interested in intercepting on the JSF lifecycle and/or the JSF component tree, not when you're only interested in its generated HTML response. There exist the JTidyFilter which does exactly what you want. Just define it once in web.xml and all the respone HTML will be prettified. All it basically does is wrapping the response.getOutputStream() to haul it through JTidy first.

BalusC
the JTidy homepage says, that it uses `<filter-class>org.w3c.tidy.servlet.filter.JTidyFilter</filter-class>`, but there are just `org.w3c.tidy` and `org.w3c.tidy.ant` packages in the downloaded jar...?
coubeatczech
Here's the [jtidyservlet.jar](http://jtidy.sourceforge.net/nightly/jtidyservlet-r8-SNAPSHOT.jar). It contains the filter as well.
BalusC