在JSF 2.0组件中包含子元素

Tuu*_*nen 10 java jsf components parameter-passing wrapper

这一定很简单.我试图将子元素传递给JSF组件.我将我的组件声明为:

<?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>
Run Code Online (Sandbox Code Playgroud)

然后我在页面中使用它:

<box:box>
    <p>Hello world!</p>
</box:box>
Run Code Online (Sandbox Code Playgroud)

不幸的是,盒子呈现好(黑色边框),但"Hello world!" 文本不包含在其中.我也通过使用<ui:insert name="content">和调用来尝试更详细的语法,<ui:define name="content">Hello World!</ui:define>但它没有用.

我哪里可能犯错?

Tuu*_*nen 12

好吧我明白了.您应该使用,<composite:insertChildren />如:

<?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>
Run Code Online (Sandbox Code Playgroud)

这有效.