问题描述
我有以下 UI Primefaces 片段:
<pou:growl id="growl"重新显示=假"显示细节=假"粘性=假"/>
当我尝试更新此项目时,例如像这样:
一切正常.
然而,当我将咆哮移动到复合组件并尝试调用它时(即像这样):
我收到一条错误消息,内容为:
javax.faces.FacesException:无法找到从j_idt84:j_idt85:testForm:j_idt111"引用的标识符为:growl"的组件.
我的问题是为什么要添加所有这些自动生成的名称,我该如何控制它们以便我可以实际访问要更新的组件?
这是因为复合组件本质上是从 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.
这篇关于JSF 更新复合组件(Primefaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!