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?
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.
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.
© 2022 - 2024 — McMap. All rights reserved.