webtier@glassfish.java.net

JSF2 how pass dataTable loop var to custom component

From: <webtier_at_javadesktop.org>
Date: Tue, 21 Sep 2010 17:41:25 PDT

I want to encapsulate a site-wide bookmarkable URL GET link strategy as a reusable component. I have a number of entity classes (Activity, Actor, Block, ..) that extend Element. Each entity class has its own Manager as managedbean.

There is a lot of repetition in the coding for table columns with links:

                <h:dataTable
                    var="actor"
                    value="#{actorManager.items}"
>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Role name"/>
                        </f:facet>
                        <h:link outcome="/#{actor.stem}/view" value="#{actor.name}">
                            <f:param name="id" value="#{actor.id}"/>
                        </h:link>
                    </h:column>
..
</h:dataTable>

I want to encapsulate the link part as a reusable component: resources/util/view_link.xhtml:

    <composite:interface>
        <composite:attribute name="element" required="true"/>
    </composite:interface>

    <composite:implementation>
        <h:link outcome="/#{cc.attrs.element.stem}/view" value="#{cc.attrs.element.name}">
            <f:param name="id" value="#{cc.attrs.element.id}"/>
           </h:link>
    </composite:implementation>

However for some reason I can't pass the dataTable loop var to the custom composite.This fails:

                <h:dataTable
                    var="actor"
                    value="#{actorManager.items}"
>
                    <h:column>
..
<util:view_link element="#{actor}"/>
                    </h:column>
..
</h:dataTable>

The error reported claims that "The following attribute(s) are required, but no values have been supplied for them: element. ", but clearly the var 'actor' is not null (I've checked).

It seems one can't pass loop variables to components this way. If so:

Q1: why not ?

Q2: is there a way around this ?

Grateful for feedback,

Webel
[Message sent by forum member 'webelcomau']

http://forums.java.net/jive/thread.jspa?messageID=483289