jsf - 将 JSF 复合组件打包到 JAR 中

标签 jsf jsf-2 xml-namespaces composite-component modularity

当试图将我们的复合组件捆绑到一个 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> 

在这里,从公共(public) 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文件夹。它实际上不存在。它实际上在里面 /common/components文件夹。

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

同时,我已经修复了您在那里找到的答案。

关于jsf - 将 JSF 复合组件打包到 JAR 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48528237/

相关文章:

jquery - Primefaces 文件上传,将文件拖放到 p :fileUpload anywhere in the page 之外

java - JSF - 获取 java.lang.NullPointerException

jsf-2 - PrettyFaces、过滤器和 url 模式问题

jsf - 如何确定组件是否在某个方面内?

xml - 为什么 xmlns :xsi, 而不仅仅是 XML 文档中的 xsi?

xml - 带有命名空间的 XPath 和 XML

javascript - JSF 中的输入文本字段验证

java - 用于 Java 服务器面孔的 web.xml

jsf - JSF2中如何指定资源库版本?

java - XPath 命名空间绑定(bind)在将其构建为文档后丢失