when I try to have them update the composite component by ID I get a "Cannot find component with identifier" exception
It's unfortunate that you didn't show how exactly you did that, because it should work just fine, provided that you used the composite's client ID in the update which is enclosed in the composite itself:
<f:ajax render=":#{cc.clientId}" />
Or, that you just used composite's own ID in the update which is performed outside the composite inside the same naming container parent:
<f:ajax render="myId" />
Most likely you did it the wrong way. E.g. you forgot the :
prefix, or you used #{cc.id}
instead of #{cc.clientId}
, etc. The above has as far as I know always worked in all Mojarra 2.x versions released so far.
See also:
- Referring composite component ID in f:ajax render
- Is it possible to update non-JSF components (plain HTML) with JSF ajax?
Alternatively, is there a way to force JSF to allow dynamic ids on components?
You can just use EL in id
attribute, provided that it's available during view build time and thus not only during view render time. See also JSTL in JSF2 Facelets... makes sense? for related background information.
Update as per your question update wherein you finally show how you tried to achieve it;
With
<ppa:myComponent id="myId" update="myId" />
and
<p:commandButton ... update="#{cc.attrs.update}" />
you're effectively ultimately doing a
<p:commandButton ... update="myId" />
which is basically looking for a component with ID myId
inside the context of the composite itself! It would only have effect on e.g. a <h:outputText id="myID">
next to the <p:commandButton>
inside the same <cc:implementation>
.
The functional requirement is understood, but the solution is not so nice. Your closest bet is (ab)using @this
and conditionally checking for that in update
:
<ppa:myComponent id="myId" update="@this" />
with something like this
<p:commandButton ... update="#{cc.attrs.update == '@this' ? ':'.concat(cc.clientId) : cc.attrs.update}" />