JSF prettify/beautify HTML output
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开发者_Go百科>
listening to RenderPhase might be the right way to go, but I don't know how to do that concretely.
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.
精彩评论