afi
afi

Reputation: 11

jsf 2 composite component problem when use f:facet

I am new to JSF, so I have many problems with it. I have solved much, but now I have a problem when I make composite component of column.

This is the code:

myPage.xhtml:

<h:dataTable  > 
    <util:myCol />
</h:dataTable>

myCol.xhtml:

<composite:interface>
</composite:interface> 
<composite:implementation>
    <h:column>
        <f:facet name="header" >
           <h:outputText value="user name" />
        </f:facet>
        <h:outputText value="some data" />
    </h:column>
</composite:implementation>

The problem is that the column does not render.

So I have changed a little in code:

myPage.xhtml:

<h:dataTable  > 
    <h:column>
        <util:myCol />
    </h:column>
</h:dataTable>

myCol.xhtml:

<composite:interface>
</composite:interface> 
<composite:implementation>
    <f:facet name="header" >
        <h:outputText value="user name" />
    </f:facet>
    <h:outputText value="some data" />
</composite:implementation>

Here the column renders, but the header "user name" does not appear.

How to solve the problem? Thanks in advance.

Upvotes: 1

Views: 4660

Answers (4)

Gijs Mollema
Gijs Mollema

Reputation: 11

I don't know if you still follow this thread, but we had problems inserting facets due to a bug. Starting the content inside the facet with a comment (server side comment < ! - - - - > ) may solve the problem showing the content. We encountered problems with facets having one liners in there.. putting an extra comment as the first statement is the workaround for the problem.

Kind regards, Gijs

Upvotes: 1

lexicore
lexicore

Reputation: 43671

Use composite:facet in interface and composite:renderFacet or composite:insertFacet in implementation.

<composite:interface>
    <composite:facet name="foo"/>
    <composite:attribute name="value"/>
</composite:interface>
<composite:implementation>
    <h:inputText id="value" value="#{cc.attrs.value}"/>
    <composite:renderFacet name="foo"/>
    <composite:insertChildren/>
</composite:implementation>

Upvotes: 0

Jon Onstott
Jon Onstott

Reputation: 13727

Does it render correctly when you have all of the JSF on one page? Setting up your JSF on a single page at first can be helpful to make sure that the basics are right; after that works, you can break it up into composite components.

Also, I have noticed (using JSF and Richfaces) that sometimes you can't separate 'parents' and 'children' at times; a rich:toolBar and it's rich:toolBarGroup's need to be on the same actual page, for example. I haven't worked with Facelets much so you might have a different situation.

Best of luck.

Edit:

Try pulling the header out of the composite control, i.e.:

<h:dataTable  > 
    <h:column>
        *HEADER_FACET_GOES_HERE*
        <util:myCol />
    </h:column>
</h:dataTable>

Upvotes: 0

McDowell
McDowell

Reputation: 108899

Case 1:

dataTable only treats column control children as columns. You are adding a composite control to the dataTable and a the column to the composite control.

Case 2:

The problem is probably to do with where the facets are set. These are set on a map on the parent control. The control you are adding the header facet to is the composite control, not the column.

Note: the links are to JSF 1.2 (JEE5) stuff, but the principle still applies.

Upvotes: 1

Related Questions