Why does a p:datatable need to prefix the root JSF IDs? Maybe it's my code, but the example posted seems minimal to me. In any case, using this will result in possibly long IDs all over the application.

1 Answer
1

PrimeFaces uses the standard JSF algorithm as provided by UIComponent#findComponent() to find components by a given client ID. The algorithm is in detail described in the aforelinked javadoc. Here's an extract of relevance:

A search expression consists of either an identifier (which is matched exactly against the id property of a UIComponent, or a series of such identifiers linked by the UINamingContainer#getSeparatorChar character value. The search algorithm should operates as follows, though alternate alogrithms may be used as long as the end result is the same:

Identify the UIComponent that will be the base for searching, by stopping as soon as one of the following conditions is met:

If the search expression begins with the the separator character (called an "absolute" search expression), the base will be the root UIComponent of the component tree. The leading separator character will be stripped off, and the remainder of the search expression will be treated as a "relative" search expression as described below.

Otherwise, if this UIComponent is a NamingContainer it will serve as the basis.

Otherwise, search up the parents of this component. If a NamingContainer is encountered, it will be the base.

Otherwise (if no NamingContainer is encountered) the root UIComponent will be the base.

The search expression (possibly modified in the previous step) is now a "relative" search expression that will be used to locate the component (if any) that has an id that matches, within the scope of the base component. The match is performed as follows:

If the search expression is a simple identifier, this value is compared to the id property, and then recursively through the facets and children of the base UIComponent (except that if a descendant NamingContainer is found, its own facets and children are not searched).

If the search expression includes more than one identifier separated by the separator character, the first identifier is used to locate a NamingContainer by the rules in the previous bullet point. Then, the findComponent() method of this NamingContainer will be called, passing the remainder of the search expression.

"reRender" uses UIComponent.findComponent() algorithm (with some additional exceptions) to find the component in the component tree.

Those additional exceptions are nowhere in detail described, but it's well known that relative component IDs (i.e. those not starting with :) are not only searched in the context of the closest parent NamingContainer, but also in all other NamingContainer components in the same view (which is a relatively expensive job by the way).