I am working on an application where I would like to include dynamic XHTML content from a stream. To handle this I wrote a taghandler extension which dumps the dynamic XHTML content to output component as
UIOutput htmlChild = (UIOutput) ctx.getFacesContext().getApplication().createComponent(UIOutput.COMPONENT_TYPE);
htmlChild.setValue(new String(outputStream.toByteArray(), "utf-8"));
This works fine for XHTML content which has no JSF tags. If I have JSF tags in my dynamic XHTML content like <h:inputText value="#{bean.item}"/>
, then they're printed as plain text. I want them to render as input fields. How can I achieve this?
My solution for JSF 2.2 and custom URLStream Handler
public class DatabaseResourceHandlerWrapper extends ResourceHandlerWrapper {
}
Essentially, you should be using an
<ui:include>
in combination with a customResourceHandler
which is able to return the resource in flavor of anURL
. So when having anOutputStream
, you should really be writing it to a (temp) file so that you can get anURL
out of it.E.g.
with
(warning: basic kickoff example! this creates a new temp file on every request, a reuse/cache system should be invented on your own)
which is registered in
faces-config.xml
as followsNote: all of above is JSF 2.2 targeted. For JSF 2.0/2.1 users stumbling upon this answer, you should use
ResourceResolver
instead for which an example is available in this answer: Obtaining Facelets templates/files from an external filesystem or database. Important note:ResourceResolver
is deprecated in JSF 2.2 in favor ofResourceHandler#createViewResource()
.