Include sub-element inside JSF 2.0 component(在 JSF 2.0 组件中包含子元素)
问题描述
这一定很简单.我正在尝试将子元素传递给 JSF 组件.我的组件声明为:
This must be simple. I am trying to pass sub-element into a JSF component. I have my component declared as:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
</composite:interface>
<composite:implementation>
<div style="border: 1px solid black;">
<ui:insert />
</div>
</composite:implementation>
</html>
然后我通过以下方式在页面中使用它:
Then I use this in a page by:
<box:box>
<p>Hello world!</p>
</box:box>
不幸的是,该框呈现正常(黑色边框),但Hello world!"文本不包含在其中.我还通过使用 <ui:insert name="content">
并通过 <ui:define name="content">Hello World!< 调用来尝试更详细的语法./ui:define>
但它不起作用.
Unfortunately, the box renders ok (the black border) but the "Hello world!" text is not included within it. I also tried more verbose syntax by using <ui:insert name="content">
and calling by <ui:define name="content">Hello World!</ui:define>
but it didn't work.
我可能会在哪里犯错?
推荐答案
好的,我想通了.您应该使用
Ok I figured it out. You should use <composite:insertChildren />
instead as in:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
</composite:interface>
<composite:implementation>
<div style="border: 1px solid black;">
<composite:insertChildren />
</div>
</composite:implementation>
</html>
这行得通.
这篇关于在 JSF 2.0 组件中包含子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 JSF 2.0 组件中包含子元素


基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01