由component.clientId和p:component()生成的客户端ID之间的区别 [英] Difference between client id generated by component.clientId and p:component()

查看:116
本文介绍了由component.clientId和p:component()生成的客户端ID之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检索位于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>

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆