tags:

views:

875

answers:

6

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.

A: 

sorry >>i mean in the question "when use "

afi
Welcome at Stackoverflow :) I have sanitized and formatted your question. Please use `edit` link to edit questions. Do not post updates or comments as **answers**.
BalusC
A: 

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>
Jon
thank youI try thatwhen i put all code in one page work finebut same problem when separate it...help me :(
afi
I modified my answer, and I think the example I've given should work for you now.
Jon
+1  A: 

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.

McDowell
thank you very much but I can not understand what must do to make my application work by use cloumn composite component with facet ...
afi
You will probably have to use the `<composite:interface componentType="...` attribute. The control you specify will probably have to be of type `UIColumn` and conform to the rules specified by this attrubute (such as being a `NamingContainer`). Since there is no such component, you'll have to write one. Details are in the JSF specification.
McDowell
what you meaning in "Since there is no such component, you'll have to write one" ...I read specification and I found UIColumn .please give me clear example about make composite Column .. thank you and I am so sorry for my questions
afi
I mean that there is no class that is a _UIColumn_ AND implements _NamingContainer_ AND is defined in a _faces-config.xml_. That is, `public class MyColumn extends UIColumn implements NamingContainer { ...` http://java.sun.com/javaee/5/docs/tutorial/doc/bnavg.html _(You shouldn't need to define any tags in this case - just the Java class and the config descriptor.)_
McDowell
I add answer(frankly it is comment)..plz show it
afi
A: 

sir McDowell I am with you but when I try this:

myPage.xhtml:

h:dataTable

     util:myCol /

/h:dataTable

in myCol.xhtml I have :

composite:interface componentType="HtmlDataTable"

/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 result is not good the data table do not apper and i get the follow:

SEVERE: JSF1068: Cannot instantiate component with component-type HtmlDataTable WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception javax.faces.FacesException: Expression Error: Named Object: HtmlDataTable not found. ..........

but htmldataTable implement NamingContainer (http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/javax/faces/component/html/HtmlDataTable.html)

I am waiting you :(

afi
A: 

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>

lexicore
A: 

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

Gijs Mollema