Difference between client id generated by component.clientId and p:component()

时光总嘲笑我的痴心妄想 提交于 2019-12-04 13:08:37
BalusC

The implicit EL object #{component} refers to the current component, which is in the case of

<h:outputText value="#{component.clientId}" />

the <h:outputText> itself!

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>

See also:

There are two premises in my answer:

  1. UIPanel class doesn't implement NamingContainer interface, thus, id of <h:panelGroup> won't end up in client id of its children;
  2. #{component} resolves to the current component in which this variable is used.

In this light in the first snippet you're outputting client id of an <h:outputText>, that is the id of its naming container plus separator plus its autogenerated id (note that you mispaced : that should be . in your #{component:clientId}), and in the second snippet you use EL function p:component of PrimeFaces that searches the whole component tree for the component with id as specified in its parameter and returns client id of the found component.

So, you look for different components: <h:outputText> in the first case and <h:panelGroup> in the second case, and that explains the difference in results.

Under current setup the following expressions will yield identical results:

  • #{component.parent.clientId} and
  • #{p:component('listItem')}.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!