在JAR中打包Facelets文件(模板,包含,复合) [英] Packaging Facelets files (templates, includes, composites) in a JAR

查看:134
本文介绍了在JAR中打包Facelets文件(模板,包含,复合)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将具有公共内容的JSF2 Facelets文件放入JAR中,以便从其他Web应用程序中使用它们。 < ui:合成模板> < ui:include src> < cc:实施> 等?如果是,我怎样才能做到这一点?是否需要一些额外的配置?

解决方案

您可以将公共资源放在 / META-INF / resources中 JAR的文件夹,它被视为WAR的 / WEB-INF / resources 文件夹。



例如

  CommonWebProject 
| - META-INF
| | - 资源
| | ` - 普通
| | | - css
| | | ` - some.css
| | | - js
| | | ` - some.js
| | | - 图片
| | | ` - some.png
| | | - 组件
| | | ` - somecomposite.xhtml
| | | - someinclude.xhtml
| | ` - sometemplate.xhtml
| | - faces-config.xml
| ` - MANIFEST.MF

然后可以按如下方式获取JAR的资源:

 < ... xmlns:common =http://xmlns.jcp。组织/ JSF /复合/普通/组件> 
< h:outputStylesheet library =commonname =css / some.css/>
< h:outputScript library =commonname =js / some.js/>
< h:graphicImage library =commonname =images / some.png/>
< common:somecomposite />
< ui:include src =/ common / someinclude.xhtml/>
< ui:composition template =/ common / sometemplate.xhtml/>
...

如果你想触发JSF2注释扫描器那么你可以放 @ManagedBean @FacesValidator @FacesConverter 和同样在该项目中进行合作,然后创建一个兼容JSF2的 /META-INF/faces-config.xml 文件:



< pre class =lang-xml prettyprint-override> <?xml version =1.0encoding =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时才需要Facelets资源解析器-INF / resources 由于某种原因,或者当你没有使用Servlet 3.0而是2.5时,或者当你使用早期的JBoss / JSF版本时,它会在META-INF资源解析中出现错误。另请参见如何创建模块化JSF 2.0应用程序?是一个具体的例子。


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?

解决方案

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.

E.g.

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
 :

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" />
...

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>

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屋!

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