Skip to main content

Facets vs children in composite components

1 reply [Last post]
rostislav
Offline
Joined: 2005-09-12

I've been doing some tests with composite components and I would like to understand why they produce different results when I use facets and children. Here are the files I'm using:

test.xhtml
-------------------------------
<p></p>

<p></p>

listFacets.xhtml
-------------------------------

#{child.attributes.styleClass}

listChildren.xhtml
-------------------------------

#{child.attributes.styleClass}

The above produce the following HTML:

<p>listFacets</p>
Test1Test2

Test1Test2

Test1Test2

test

test

<p>listChildren</p>
Test1Test2

So, when using a single facet I'm able to print it multiple times inside a loop but the composite:insertChildren is printed only one. The children are printed multiple times when I replace c:forEach with ui:repeat but I really prefer using c:forEach. I had to check again but ui:repeat worked well in Jetty 6.1.18 but throw an exception in Tomcat 6.0.16.

Another cool feature of the facet is that I can access it's children and their attributes using the cc.facets.content.children collection. I wasn't able to achieve the same using the children variant. A bug I also noticed when doing the tests is that when there is a single child inside the facet the cc.facets.content.children doesn't work as expected. It works fine when there are multiple children inside the facet.

I'm wondering is this behavior expected by design. I don't need the single facet if I can use the composite:insertChildren functionality but so far the facet approach only satisfies my needs.

Any hints on formatting code in this forums are also welcome

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rostislav
Offline
Joined: 2005-09-12

I was able to achieve what I wanted using a custom Faces component. I'm using a mixture of the JSTL core and Facelets UI tags which somehow leads to an empty children collection in composite components. Here is the code I'm using as a componentType of my composite interface:

@FacesComponent(value = "faces.CompositeComponent")
public class CompositeComponent extends UINamingContainer {

private List children;

public Iterator getFacetsAndChildren() {
Iterator iterator = super.getFacetsAndChildren();
List superChildren = super.getChildren();
if (children == null || (children != null && children.size() < superChildren.size())) {
children = new ArrayList();
for (UIComponent c : superChildren) {
children.add(c);
}
}
return iterator;
}

public List getChildren() {
return children;
}
}