Search code examples
jsfjsf-2composite-component

How to set <cc:clientBehavior targets> to <p:commandLink> inside <p:dataList>


I have a problem with the JSF composite cc:clientBehavior's targets attribute.

The main question is:

What should I write to the behavior "targets" to work with all of the list elements?

My sample code:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:cc="http://xmlns.jcp.org/jsf/composite"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">
<cc:interface>
    <cc:attribute name="items" />
    <cc:clientBehavior name="itemClick" targets="???" event="click" />
</cc:interface>

<cc:implementation>
    <!-- or ui:repeat or c:forEach... -->
    <p:dataList id="itemList" value="#{cc.attrs.items}" var="item">
            <p:outputLabel value="#{item.id}" />
            <p:commandLink id="itemLink" value="view details" >
                <f:attribute name="clicked" value="#{item.id}" />
            </p:commandLink>
    </p:dataList>
</cc:implementation>


Solution

  • Just use a composite-component-implementation-relative client ID pointing to the <p:commandLink>.

    <cc:clientBehavior name="itemClick" targets="itemList:itemLink" event="click" />
    

    Note that this wouldn't have worked with <c:forEach>. See also JSTL in JSF2 Facelets... makes sense?