【问题标题】:Package JSF Composite Component into JAR将 JSF 复合组件打包成 JAR
【发布时间】:2018-07-09 17:46:57
【问题描述】:

当尝试将我们的复合组件捆绑到一个 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”工作正常,但标签没有工作。检查页面只显示标签。

有什么想法吗?

【问题讨论】:

  • 直接在项目中包含所有内容时是否有效?您的 faces-config.xml 中有什么特别之处吗?您的 web.xml 中有什么特别之处吗?版本?

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


【解决方案1】:
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 />

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

【讨论】:

  • 好的,太好了!我有那个工作。如果我想包含 java 类,它们是否也属于“组件”文件夹?
  • @BalusC 恭喜您成为 Stackoverflow 的第二大用户。你真的值得拥有。
  • @Eng.Fouad:谢谢 :)
猜你喜欢
  • 2013-01-07
  • 2011-11-09
  • 1970-01-01
  • 2015-06-10
  • 1970-01-01
  • 2011-06-27
  • 1970-01-01
  • 2011-04-01
相关资源
最近更新 更多