JSF facelets 模板打包 [英] JSF facelets template packaging

查看:33
本文介绍了JSF facelets 模板打包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一如既往,我有点困惑.

As always, i'm a little confused.

这里 https://community.jboss.org/wiki/ModularWebAppsWithJSF2了解到自 JSF 2.0 以来,将模板捆绑在单独的 jar 中很容易并且开箱即用.

Here https://community.jboss.org/wiki/ModularWebAppsWithJSF2 i've learned that it is easy and works out of the box to bundle templates in separate jars since JSF 2.0.

唯一的问题是:我无法让它工作.我只是在包含在 Web 应用程序 WEB-INF/lib 中的 jar 中部署所有风格的page.xhtml"(META-INF 目录、资源目录、根目录;有和没有faces-config.xml)并请求一些东西像 http://host/demo/faces/page.xhtml 或做一个包含"或在模板上装饰".我有一个例外.

The only problem is: i can't get it working. I simply deploy a "page.xhtml" in all flavors (META-INF directory, resources directory, root; with and without faces-config.xml) in a jar that is included in the web application WEB-INF/lib and request something like http://host/demo/faces/page.xhtml or do an "include" or "decorate" on the template. I get an exception.

这里 Java EE6>将 JSF facelets (xhtml) 和 ManagedBeans 打包为 JAR 我最喜欢的 JSF 老师解释说使用自定义 ResourceResolver 来完成此操作.当我调试资源解析时,我毫不怀疑这会起作用并且会尝试一下.

Here Java EE6> Packaging JSF facelets (xhtml) and ManagedBeans as JAR my favorite JSF teacher explains to use a custom ResourceResolver to do exactly this. As i debugged the resource resolving i have no doubt that this will work and will give it a try.

这是关于机制的问题——这两种方法有什么区别?

This is the question about the mechanics - what is the difference between the two approaches?

在 META-INF/resources 中自动查找哪些资源?

Which resources exactly are looked up in META-INF/resources automatically?

推荐答案

Facelets composition(因此,只是简单的 *.xhtml 页面、模板和包含文件)得到解决来自 ExternalContext#getResource() 委托给 ServletContext#getResource().这需要一个与 Servlet 3.x 兼容的容器,因为 /WEB-INF/lib/*.jar!/META-INF/resources 从 Servlet 3.0 开始是新的.如果您还没有使用 Servlet 3.x,或者出于某种原因想要将这些 JAR 放在不同的位置,那么您需要创建一个自定义 ResourceResolver.另请参阅如何创建模块化 JSF 2.0 应用程序?

Facelets compositions (so, just plain *.xhtml pages, templates and include files) are resolved by ExternalContext#getResource() which delegates to ServletContext#getResource(). This requires a Servlet 3.x compatible container because /WEB-INF/lib/*.jar!/META-INF/resources resolving from is new since Servlet 3.0. If you aren't on Servlet 3.x yet, or want to put those JARs on a different location for some reason, then you'd need to create a custom ResourceResolver. See also How to create a modular JSF 2.0 application?

Facelets 复合组件和静态资源(因此, 组件和 CSS/JS/图像资源将由 <;h:outputStylesheet>) 由 ClassLoader#getResource().要在 JSF 的类路径扫描中包含 JAR 文件,您需要在 /META-INF 中包含一个与 JSF 2.x 兼容的 faces-config.xml 文件JAR 文件的文件夹.同样的故事适用于 @ManagedBean@FacesValidator@FacesConverter@FacesComponent 和其他 JSF 工件.

Facelets composite components and static resources (so, <cc:xxx> components and CSS/JS/image resources which are to be loaded by <h:outputStylesheet>, <h:outputScript> and <h:graphicImage>) are resolved from the classpath by ClassLoader#getResource(). To include the JAR file in the classpath scan of JSF, you'd need to include a JSF 2.x compatible faces-config.xml file in the /META-INF folder of the JAR file. The same story applies to @ManagedBean, @FacesValidator, @FacesConverter, @FacesComponent and other JSF artifacts.

在Eclipse中开发时,可以选择Web > Web Fragment Project来创建这样的模块项目.它与普通的 Java 项目 没有太大区别,期望它会隐式地包含 JavaScript 方面和目标运行时,自动创建一个 /META-INF/web-fragment.xml文件并通过将自身作为部署程序集添加到该项目来与现有的动态 Web 项目相关联.

When developing in Eclipse, you can choose Web > Web Fragment Project to create such a module project. It is not much different from a normal Java project, expect that it will implicitly include JavaScript facet and a targeted runtime, autocreate a /META-INF/web-fragment.xml file and get associated with an existing Dynamic Web Project by adding itself as a deployment assembly to that project.

您还可以使用现有的标准 Java 项目,并准备好正确的文件夹结构./META-INF 文件夹必须位于 Java 源文件夹中.web-fragment.xml 文件是可选的.您只需要手动将 Java 项目添加到主 Web 项目属性的Deployment Assembly 部分.不要不要将它作为另一个项目添加到项目的构建路径部分.

You can also use an existing standard Java project with the right folder structure prepared. The /META-INF folder has to go in Java source folder. The web-fragment.xml file is by the way optional. You just have to manually add the Java project to the Deployment Assembly section of the main web project properties. Do not add it as another project in project's Build Path section.

当您(手动)从中构建 JAR 文件时,您需要确保将目录条目添加到 JAR 中,否则无法解析 Facelets 组合.如果您使用 Eclipse/Ant/Maven/等构建工具进行构建,则也必须考虑到这一点.如果这是不可控的,自定义 ResourceResolver 是最可靠的方法.

When you're (manually) building a JAR file out of it, you need to make sure that the directory entries are added to the JAR, otherwise Facelets compositions can't be resolved. If you're building by build tools like Eclipse/Ant/Maven/etc, this has also to be taken into account. If this is not controllable, a custom ResourceResolver is the most reliable approach.

这篇关于JSF facelets 模板打包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆