更新时间:2022-10-15 08:04:58
这是因为复合组件本质上是从 UINamingContainer
(如、
等),从而在孩子的客户端 ID 前面加上自己的 ID.
为了实现您的特定功能需求,首先为您的复合组件提供一个固定 ID:
<ez:growl id="growl"/>
然后将
嵌入到复合组件的实现中,例如
以复合组件的客户端 ID 作为元素 ID:<span id="#{cc.clientId}"><p:咆哮/></span></cc:实施>
现在您可以按照通常的方式使用 update=":growl"
.
I have the following UI Primefaces snippet:
<pou:growl id="growl"
redisplay="false"
showDetail="false"
sticky="false" />
When I try to update this item, for example like this:
<pou:commandButton value="Update"
update=":growl"/>
Everything works fine.
When I move growl to a composite component however and try to call it (ie. like this):
<ez:growl/>
I get an error maessage that says:
javax.faces.FacesException: Cannot find component with identifier ":growl" referenced from "j_idt84:j_idt85:testForm:j_idt111".
My question is why are all these auto generated names being added and how can I control them so I can actually access the components to update?
It's because composite components inherently extend from UINamingContainer
(like as <h:form>
, <h:dataTable>
, etc) and thus prepend the client ID of their children with own ID.
To achieve your particular functional requirement, first give your composite component a fixed ID:
<ez:growl id="growl"/>
Then embed the <p:growl>
in the composite component's implementation in a plain HTML container element like <div>
or <span>
with the composite component's client ID as element ID:
<cc:implementation>
<span id="#{cc.clientId}">
<p:growl />
</span>
</cc:implementation>
Now you can just use update=":growl"
the usual way.