在 JAR 中打包 Facelets 文件(模板、包含、组合) [英] Packaging Facelets files (templates, includes, composites) in a JAR
问题描述
是否可以将具有通用内容的 JSF2 Facelets 文件放入 JAR 中,以便在其他 Web 应用程序中使用它,例如
、
、
等?如果是,我怎样才能做到这一点?是否需要一些额外的配置?
Is it possible to put JSF2 Facelets files with common content into a JAR to use it from other web applications inside e.g. <ui:composition template>
, <ui:include src>
, <cc:implementation>
, etc? If yes, how can I achieve this? Is some extra configuration necessary?
推荐答案
您可以将公共资源放在 JAR 的 /META-INF/resources
文件夹中,该文件夹将被视为 /WEB-INF/resources
WAR 文件夹.
You can put common resources in the /META-INF/resources
folder of the JAR which is to be treated like as /WEB-INF/resources
folder of the WAR.
例如
CommonWebProject
|-- META-INF
| |-- resources
| | `-- common
| | |-- css
| | | `-- some.css
| | |-- js
| | | `-- some.js
| | |-- images
| | | `-- some.png
| | |-- components
| | | `-- somecomposite.xhtml
| | |-- someinclude.xhtml
| | `-- sometemplate.xhtml
| |-- faces-config.xml
| `-- MANIFEST.MF
:
JAR 的资源如下所示:
The resources of the JAR are then available as follows:
<... xmlns:common="http://xmlns.jcp.org/jsf/composite/common/components">
<h:outputStylesheet library="common" name="css/some.css" />
<h:outputScript library="common" name="js/some.js" />
<h:graphicImage library="common" name="images/some.png" />
<common:somecomposite />
<ui:include src="/common/someinclude.xhtml" />
<ui:composition template="/common/sometemplate.xhtml" />
...
如果您还想触发 JSF2 注释扫描器,以便您可以放置 @ManagedBean
、@FacesValidator
、@FacesConverter
和 consorts在该项目中,然后创建一个与 JSF2 兼容的 /META-INF/faces-config.xml
文件:
If you want to trigger the JSF2 annotation scanner as well so that you can put @ManagedBean
, @FacesValidator
, @FacesConverter
and consorts in that project as well, then create a JSF2 compatible /META-INF/faces-config.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
仅当资源由于某种原因不在 /META-INF/resources
中时,或者当您使用的不是 Servlet 3.0 而是 2.5 时,或者当您使用使用早期的 JBoss/JSF 版本,该版本在 META-INF 资源解析中存在错误.另请参阅如何创建模块化 JSF 2.0 应用程序? 举个具体的例子.
The Facelets resource resolver is only necessary if the resources are not in /META-INF/resources
for some reason, or when you're not using Servlet 3.0 but 2.5, or when you're using an early JBoss/JSF version which has bugs in META-INF resource resolving. See also How to create a modular JSF 2.0 application? for a concrete example.
这篇关于在 JAR 中打包 Facelets 文件(模板、包含、组合)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!