I'm finishing on learning the Java language and looking to write very small web applications, since Facelets seems to be the replacement for JSP, and JSF seems overkill for small web apps, can I just learn Facelets and use it without the whole JSF stack? or should I just go with JSP for this small web apps?
-
1Would you like to read [this](http://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp/2097732#2097732) and [this](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202) questions? – Lion Jul 19 '12 at 21:06
-
3I read those but they don't really say if facelets can be use as a standalone technology. – Der Jul 19 '12 at 21:43
2 Answers
It can be used without JSF. Just map the FacesServlet
on an URL pattern of *.xhtml
in web.xml
and do not declare
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
in any Facelet template. It actually don't harm to declare them, but this way you won't "accidentally" use them. You can as good write plain HTML in it and submit the form to a plain servlet and have the servlet forward/redirect to a Facelet.
You only need to keep in mind that with a servlet you end up with much more boilerplate code for gathering the request parameters, converting/validating them, maintaining and updating the model values, invoking the business actions, while all this repeated boilerplate code is unnecessary with a fullworthy JSF managed bean.
Also, you can't use Facelets with request based MVC frameworks which have only JSP taglibs available, like Struts, Spring MVC, etc.

- 1,082,665
- 372
- 3,610
- 3,555
-
1Well you still need the whole jsf jar isn't it? Also, when f: and h: is not used, what templating options are left to the developer? Isn't ui considered as a part of jsf for example? – Koray Tugay Oct 05 '14 at 15:31
-
Why did you say do not declare xmlns:f and :h only? And what can you do without using these tags in a facelets page? Only el is available then? – Koray Tugay Oct 05 '14 at 21:18
-
No I mean why did not you say "do not declare ui:" as well? Why did you say do not declare f: and h: only? – Koray Tugay Oct 06 '14 at 06:22
Facelets is developed for the need of JSF and as so is dependent on JSF. If you need templating for JSP simply use <@import>, or more advanced library as Apache Tiles.

- 4,722
- 3
- 31
- 53