微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将JSF Composite Component打包到JAR中

在尝试将我们的复合组件捆绑到一个jar中并作为依赖项包含在另一个项目中时,我遵循了 following answer.

这适用于除复合组件实现之外的所有内容.
我们常见项目的文件夹结构如下所示:

CommonWebProject
 |-- meta-inf
 |    |-- resources
 |    |    `-- common
 |    |         |-- css
 |    |         |    ...
 |    |         |-- js
 |    |         |    ...
 |    |         |-- components
 |    |         |    `-- comment.xhtml
 |    |         |-- templates
 |    |         |    `-- defaultTemplate.xhtml
 |    |-- faces-config.xml
 |    `-- MANIFEST.MF
 :

comment.xhtml包括

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>

</composite:interface>

<composite:implementation>
  <p>TESTING!</p>
</composite:implementation>

</html>

实际实现如下:

<?xml version="1.0" encoding="UTF-8" ?>
  <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:csxc="http://java.sun.com/jsf/composite/csxcomponent" xmlns:p="http://primefaces.org/ui"
    xmlns:common="http://java.sun.com/jsf/composite/common"
    template="/common/templates/defaultTemplate.xhtml">
    <ui:define name="head">
    </ui:define>

    <common:comment/>

  </ui:composition>

这里从普通jar中提取的模板“defaultTemplate.xhtml”正常工作,但不是标签.检查页面显示标签.

enter image description here

有什么想法吗?

解决方法

CommonWebProject
 |-- meta-inf
 |    |-- resources
 |    |    `-- common
 |    |         |-- components
 |    |         |    `-- comment.xhtml
 :    :         :

因此,资源相对路径是/common/components/comment.xhtml.

然而,

xmlns:common="http://java.sun.com/jsf/composite/common"
...
<common:comment />

XML命名空间基本上表示comment.xhtml是在/ common文件夹中.它实际上并不存在.它实际上在inside / common / components文件夹中.

对齐它.

xmlns:common="http://java.sun.com/jsf/composite/common/components"
...
<common:comment />

我同时修复了你在那里找到的答案.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。