title: Using id-attribute in JSF 2 composite component with targets
body: <p>I am trying to create a JSF 2.1 composite component for a button:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:composite="http://java.sun.com/jsf/composite"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:c="http://java.sun.com/jstl/core"&gt;
  
      &lt;composite:interface&gt;
          &lt;composite:attribute name="id" required="true" type="java.lang.String" /&gt;
          &lt;composite:attribute name="label" required="true" type="java.lang.String" /&gt;
          &lt;composite:attribute name="action" method-signature="java.lang.String action()" targets="#{cc.attrs.id}" /&gt;
      &lt;/composite:interface&gt;
  
      &lt;composite:implementation&gt;
          &lt;a4j:commandLink id="#{cc.attrs.id}"&gt;
              &lt;span style="linkButton"&gt;&lt;h:outputText value="#{cc.attrs.label}" /&gt;&lt;/span&gt;
          &lt;/a4j:commandLink&gt;
      &lt;/composite:implementation&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem I have with this code is that it gives the following exception when the page is rendered:</p>
  
  <pre><code>java.lang.ClassCastException: javax.faces.component.UINamingContainer cannot be cast to javax.faces.component.ActionSource2
  at com.sun.faces.application.view.FaceletViewHandlingStrategy$MethodRetargetHandlerManager$ActionRegargetHandler.retarget(FaceletViewHandlingStrategy.java:1536)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.retargetMethodExpressions(FaceletViewHandlingStrategy.java:689)
  at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyNextHandler(CompositeComponentTagHandler.java:201)
  at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
  at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:196)
  ...
  </code></pre>
  
  <p>When I replace the <code>#{cc.attrs.id}</code> in <code>id</code> and <code>targets</code> attribute with a defined String like <code>myId</code> then the component works as expected but this makes it not reusable in the same page and thus eliminates the wohle sense in creating a composite component in the first place.</p>
  
  <p>Did I miss anything here?</p>