问题描述
我正在尝试检索位于p:dataList内的h:panelGroup的客户端ID.
I am trying to retrieve the client id of a h:panelGroup that is within a p:dataList.
我尝试了2种方法:
1.使用component.clientId例如:
1.Using component.clientId e.g:
<h:panelGroup id="listItem">
<h:outputText value="#{component.clientId}" />
</h:panelGroup>
2.使用p:component()例如:
2.Using p:component() e.g:
<h:panelGroup id="listItem">
<h:outputText value="#{p:component('listItem')}" />
</h:panelGroup>
请注意,该面板组在数据列表中.现在,两种情况下生成的客户端ID是不同的. (1)在客户端ID上未附加值'listItem',而(2)在生成的clientId中具有值'listItem'.
Please note that this panel group is within a datalist. Now, the client ids generates in both the cases is different. (1) does not have the value 'listItem' appended to the client id while (2) has the value 'listItem' in the generated clientId.
此外,使用(1)生成的客户端ID与生成的html组件上的客户端ID不同.
Also, the client id generated using (1) is different from that on the generated html component.
有人可以就这个问题阐明一些问题吗?
Could anyone shed some light on this issue as to why is this so ?
推荐答案
隐式EL对象#{component}
指的是当前组件,在这种情况下,
The implicit EL object #{component}
refers to the current component, which is in the case of
<h:outputText value="#{component.clientId}" />
<h:outputText>
本身!
如果要打印另一个组件的客户端ID,则需要通过binding
将组件实例绑定到视图中的唯一变量,以便可以在同一视图中的其他任何地方引用它.
If you intend to print the client ID of another component, then you need to bind the component instance to an unique variable in the view by binding
, so that you can reference it anywhere else in the same view.
<h:panelGroup id="listItem" binding="#{listItem}">
<h:outputText value="#{listItem.clientId}" />
</h:panelGroup>
另请参见:
- 含糊的EL对象
- 在JSF中'binding'属性如何工作?何时以及如何使用?
- Implicit EL objects
- How does the 'binding' attribute work in JSF? When and how should it be used?
See also:
这篇关于由component.clientId和p:component()生成的客户端ID之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!