Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to retrieve the client id of a h:panelGroup that is within a p:dataList.

I tried 2 approaches:

1.Using component.clientId e.g:

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

2.Using p:component() e.g:

<h:panelGroup id="listItem">
    <h:outputText value="#{p:component('listItem')}" />
</h:panelGroup>

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.

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 ?

like image 385
Rahul Nair Avatar asked Mar 21 '23 08:03

Rahul Nair


1 Answers

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:

  • Implicit EL objects
  • How does the 'binding' attribute work in JSF? When and how should it be used?
like image 171
BalusC Avatar answered Apr 05 '23 15:04

BalusC