I'd like to use Facelets to generate HTML contents. I want to reuse existing taglibs, which isn't supported by Velocity.
开发者_如何转开发I have read the developer's guide, but didn't get a clue.
Does Facelets need a Java compiler to work? (I guess not) I've also tried with Jetty ServletTester, but it seems not work.
So is it possible?
Yes, it's possible.
It's not necessary to have a Java compiler to render the view. Facelets is completely taglib-driven, only EL (expression language) may be occurred in the template script, so nothing needs to be static compiled.
To embed Facelets in a standalone application, you can programmatic initialize a servlet context. I'm using Jetty in this case. See the implementation of ServletTester
class, and write you own server.
It's valuable to mention that jsf-ri
doesn't work well, however, luckily we have another choice, we can use myfaces-impl
which does better.
The main problem remains is about ResourceResolver
. If you need to setup a complicated resource structure, i.e., the template files (xhtml) are placed in different locations, then you need to:
Create your own
ResourceResolver
delegatesDefaultResourceResolver
.Override
org.mortbay.jetty.servlet.Context.getResource()
to make it returns consistent resources with theResourceResolver
. Or similar ones if the embedded servlet context isn't Jetty-based.
精彩评论