JSF Facelets模板包装 [英] JSF facelets template packaging

查看:132
本文介绍了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中以各种方式(META-INF目录,资源目录,根目录;带和不带faces-config.xml)部署了一个"page.xhtml",并请求例如 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老师解释说,将JSF facelets(xhtml)和ManagedBeans打包为JAR ,我解释说要使用自定义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组成(因此,仅普通的*.xhtml页面,模板和包含文件)由 .这需要一个与Servlet 3.x兼容的容器,因为/WEB-INF/lib/*.jar!/META-INF/resources解析是自Servlet 3.0以来的新增功能.如果您尚未使用Servlet 3.x,或者出于某种原因想要将这些JAR放在其他位置,则需要创建自定义如何创建模块化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复合组件和静态资源(因此,<cc:xxx>组件和CSS/JS/图像资源将由<h:outputStylesheet><h:outputScript><h:graphicImage>加载)从类路径中通过

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 部分.不要在项目的 Build Path 部分中将其添加为另一个项目.

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/etc之类的构建工具进行构建,则也必须考虑到这一点.如果这是不可控制的,那么自定义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天全站免登陆