2

I'm currently changing the structure of one of my primefaces 6.1 based project's core subviews for a Proof of Concept and found lots of references like X:Y:Z:A, X:Y:Z:B, etc... that were obviously failing after moving the referenced components elsewhere in the tree so my solution was to replace the "long id path" by p:component('A') and so on. After several replacements some questions came to my mind: "Why didn't they just use p:component()?", "Were them intentionally referred this way...if so why?". And finally the most important - THIS. Is there any difference between calling a component with its ID and its ancestors like X:Y:Z:A and using p:component('A')??

Considering also the following scenario... what would p:component('x') return? Would there be any collision or ambiguity exception?

 <f:view>
    <h:outputText id="x" />
    <h:form id="form1">
      <h:outputText id="x" />
    </h:form>
  </f:view>

Thanks in advance

Isidro.rn
  • 195
  • 1
  • 12
  • 2
    PFS ftw https://stackoverflow.com/q/20080861 .. E.g. `update="@(.updateOnChangeFoo)"` and give these a `styleClass="updateOnChangeFoo"` and you never need to worry about changes in the component tree. – BalusC Oct 09 '19 at 11:23

1 Answers1

2

A few things...

  1. p:component find the "first" reference it can find and returns it so I believe it would find the first h:outputText.

  2. p:component has been deprecated and is has been removed for the upcoming PF 7.1 release you can see here in the Migration Guide notes: https://github.com/primefaces/primefaces/wiki/Migration-Guide

So to answer you are better off either referencing it directly with :form1:x or if you want p:component behavior where it find the first you can use PFS Selector Framework @root:@id(x) See examples here: https://www.primefaces.org/showcase/ui/ajax/selector.xhtml

Melloware
  • 10,435
  • 2
  • 32
  • 62