简体   繁体   English

Facelets作为JSP中的模板框架

[英]Facelets as a templating framework in JSP

I am very fond of the Facelets templating model. 我非常喜欢Facelets模板模型。 On the other hand there are many applications where plain old JSTL in JSPs is just fine and JSF would be an overkill. 另一方面,有许多应用程序,其中JSP中的普通旧JSTL很好,而JSF将是一种矫枉过正。

Is it possible to use Facelets in pure JSP projects, that is no JSF dependencies of any kind. 是否可以在纯JSP项目中使用Facelets,这不是任何类型的JSF依赖项。

PS. PS。 I know there is sitemesh, but still Facelets are very appealing to me. 我知道有sitemesh,但Facelets对我很有吸引力。

No, this is not possible. 不,这是不可能的。 Facelets is not exactly a templating framework, but an entirely distinct view technology and basically the successor of JSP. Facelets不是一个模板框架,而是一个完全独特的视图技术,基本上是JSP的后继者。 You can use them together in a single project when used separately , but you cannot use Facelets tags inside JSP files. 您可以单独使用时,在一个项目中同时使用它们,但你不能使用JSP文件内Facelets标记。 Facelets is not a JSP tag library, but a whole view technology at its own like as JSP is. Facelets不是JSP标记库,而是像JSP一样的整个视图技术。 Sitemesh for example is not a view technology, but a JSP tag library which can thus be imported and used in JSP by <%@taglib%> . 例如,Sitemesh不是视图技术,而是JSP标记库,因此可以通过<%@taglib%>在JSP中导入和使用它。

If you want to use Facelets, you've got to replace the JSP files altogether. 如果要使用Facelets,则必须完全替换JSP文件。 Facelets can also be used without any necessary JSF managed beans if you have only static views. 如果只有静态视图,也可以在没有任何必要的JSF托管bean的情况下使用Facelets。 There's not really a means of overkill as long as you write exactly the code you really need. 只要你准确地编写你真正需要的代码,就没有真正的矫枉过正的手段。 So JSF being a overkill is a non-argument. 所以JSF是一种矫枉过正是一种非争论。 All you need to do is to put one javax-faces.jar file in /WEB-INF/lib . 您需要做的就是将一个javax-faces.jar文件放在/WEB-INF/lib JSF 2.1 will auto-register itself on a servlet 3.0 container. JSF 2.1将在servlet 3.0容器上自动注册。 You only need to declare the FacesServlet explicitly in web.xml whenever you want to use the *.xhtml URL pattern (the default patterns are /faces/* , *.faces and *.jsf ). 只要您想使用*.xhtml URL模式(默认模式是/faces/**.faces*.jsf ),您只需要在web.xml显式声明FacesServlet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM