gpt4 book ai didi

jsf-2.2 - 如何在 JSF 2.2 中创建包含自定义标记和复合组件的干净标记库 (.jar)?

转载 作者:行者123 更新时间:2023-12-03 19:34:57 24 4
gpt4 key购买 nike

我已经阅读了关于如何在 Web 应用程序中创建复合组件和自定义标签的各种博客文章和 stackoverflow 文章,并且已经让一切正常工作。我现在正在尝试将所有内容移动到可重用的 JAR 文件中。

mylib.jar 层次结构:

src/main/java
com.example.MyComposite.java
src/main/resources/
META-INF
faces-config.xml
my.taglib.xml
META-INF/resources/components
myComposite.xhtml
META-INF/tags
myTag.xhtml

my.taglib.xml:
<facelet-taglib version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">

<namespace>http://www.example.com/components</namespace>

<tag>
<tag-name>myTag</tag-name>
<source>
tags/myTag.xhtml
</source>
</tag>

<tag>
<tag-name>myComposite</tag-name>
<component>
<resource-id>
components/myComposite.xhtml
</resource-id>
</component>
</tag>
</facelet-taglib>

我已经将它构建为一个 jar 并在我的 web 应用程序中使用它,并且自定义标记和复合组件都运行良好。尽管如此,我还是尝试了 100 种不同的层次结构组合才能让它发挥作用。

我的问题是我不喜欢我似乎必须将自定义标签放在一个地方 (/tags) 并将复合组件放在另一个地方 (/resources/components)。此外,我必须使用 引用自定义标签。来源使用 标记和复合组件组件 / 资源 ID 标签。例如,我尝试将 myTag.xhtml 放入/resources/components 并使用资源 ID 引用它,但是当我尝试使用它时却得到了 NPE。

那么标签和组件必须在不同的目录中吗?我只需要忍受这种等级制度吗?

最佳答案

您可以使用 <composite-library-name>单独用于复合 Material 以减少不必要的<tag>复合 Material 的样板。至于标签文件,你可以把它们放在/resources/tags并更改 <source>因此文件夹结构更加统一。

src/main/java
`-- com/example/MyComposite.java

src/main/resources
`-- META-INF
|-- resources
| |-- components
| | `-- myComposite.xhtml
| `-- tags
| `-- myTag.xhtml
|-- faces-config.xml
`-- my.taglib.xml

<facelet-taglib version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">

<namespace>http://www.example.com/components</namespace>
<composite-library-name>components</composite-library-name>

<tag>
<tag-name>myTag</tag-name>
<source>resources/tags/myTag.xhtml</source>
</tag>
</facelet-taglib>

也可以看看:
  • Change composite-component's namespace
  • 关于jsf-2.2 - 如何在 JSF 2.2 中创建包含自定义标记和复合组件的干净标记库 (.jar)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32017640/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com