I would like to store the response generated by the encodeAll() method of a UIComponent into a string to use the content somewhere else.
I alread tried to set up a FacesContextWrapper which provides a special ResponseWriter that should write the content to a开发者_如何学Python StringWriter, but it does not work. It seems my ResponseWriter is never called.
I know there is the other way and encode in the right place and probably I will do so, but I would still like to know how to do that. Especially the compression of the content, there should be no spaces between tags and no linebreaks, is very important.
EDIT:
I have some facets and the content of these is used to be passed to javascript, because of that i would need the rendered content of the facets to be compressed to a single line. First i tried to wrap around the writer to get the content, then compress it myself and append it to the javascript as parameter, but it didn't work. Now i render the content at the right place, but it's not compressed to a single line.
EDIT2:
Javascript Strings can only be multilined if "\n\" is used at the end of the line. I can't change the content produced by the encodeAll() method so it's really hard. I really will have to capture the content that is generated and then manually compress the string! But how to do that? ResponseWriter-wrapping did not work for me.
SOLUTION:
I would like to share my solution with others!
ResponseWriter offers a method called cloneWithWriter(Writer w)
which i didn't know. By using this method with a custom StringWriter implementation you can capture the output in a buffer and finally use that buffer as string
精彩评论