Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include sub-element inside JSF 2.0 component

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>

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.

Where might I be making a mistake?

like image 402
Tuukka Mustonen Avatar asked Aug 13 '10 07:08

Tuukka Mustonen


1 Answers

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>

This works.

like image 101
Tuukka Mustonen Avatar answered Nov 01 '22 21:11

Tuukka Mustonen