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.
Asked
Active
Viewed 1,949 times
1

BalusC
- 1,082,665
- 372
- 3,610
- 3,555

ryskajakub
- 6,351
- 8
- 45
- 75
1 Answers
3
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
- 1,082,665
- 372
- 3,610
- 3,555
-
2the JTidy homepage says, that it uses `
org.w3c.tidy.servlet.filter.JTidyFilter `, but there are just `org.w3c.tidy` and `org.w3c.tidy.ant` packages in the downloaded jar...? – ryskajakub Sep 01 '10 at 15:11 -
3Here's the [jtidyservlet.jar](http://jtidy.sourceforge.net/nightly/jtidyservlet-r8-SNAPSHOT.jar). It contains the filter as well. – BalusC Sep 01 '10 at 16:10