I want to use Facelets to build a static HTML prototype. This prototype will be sent out to people who do not have a running web application server such as Tomcat. Is there some way to compile a Facelets site at build-time (using Ant etc) into a set of flat HTML files?
In t开发者_运维问答he simplest case we have two facelets like this:
<!-- layoutFacelet.xhtml -->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:insert name="content" />
</ui:composition>
<!-- implementationFacelet.xhtml -->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="layoutFacelet.xhtml">
<ui:define name="content">
HELLO WORLD
</ui:define>
</ui:composition>
The output would be a single html (e.g. "implementationFacelet.output.html") like:
HELLO WORLD
In other words, Facelets is running at build-time rather than render-time, in order to produce static flat-file prototypes.
I'm not sure about any ready to use solution for your problem. However I have a rather good idea how it could be implemented thanks to working on a build-time JSF EL validator, where I'm currently adding support for facelets. I'd do this:
- Set up the backing beans etc. used in EL expressions - there are multiple ways to do it, I'd personally consider pluging in my "value faking EL resolver" but you may equally well just make sure that JSF can find your backing beans and somewhow ensure all the values needed are set
- Compile a view manually and build its component tree (implemented - see ExperimentalFaceletsElFinder.verifyExpressionsViaComponentTree)
- Render the component tree to HTML via UIViewRoot.encodeAll(context) - see org.apache.myfaces.view.facelets.FaceletViewHandler#renderView
So this is feasible but perhaps too much work for somebody who hasn't been working with these things before. Once I'm done with my Facelets support, I'll consider adding such functionality to the validator as it would be quite easy for me then.
Best regards, Jakub
精彩评论