This question already has an answer here:
What are the possible naming containers in PrimeFaces? Why it is necessary to append naming container id for Ajax update call when we want to update some UI control on form using update=":mainForm:MainAccordian:userNameTextbox"
?
In JSF naming containers derive from UINamingContainer.
Lets say,
<h:outputText value="test1" id="userNameTextbox" />
and you add another<h:outputText value="test2" id="userNameTextbox" />
to your page, you will get an error which says that you have a duplicate ID. You can look it up here at the JavaDoc for UIComponent.setId(String):.. furthermore, important for you:
Means that you cannot have two components with the same ID under the same NamingContainer (if you have no NamingContainer at all, the entire tree is counted as NamingContainer). Therefore you need to add a NamingContainer, like a
<h:form id="myNamingContainer" />
Lets take following example:
.. and you want to do an update to userNameTextbox. Which userNameTextbox are you refering to because there are 3?
The first one? Then update userNameTextbox
The second one? Then update container1:userNameTextbox
The third one? Then update container2:userNameTextbox
Naming Containers in Prime Faces
As we can see in JSF Reference
So to find Naming Containers in PF you need to check hierarchy of NamingContainer interface. In Eclipse you can do this for example by Ctrl+T shortcut on NamingContainer.
In PF 5.3 there are for example: AccordionPanel, Carousel, Columns, DataGrid, DataList, DataScroller, DataTable, Ring, SubTable, TabView, Tree, TreeTable.
Naming Container influence on component id
Naming Container provide a naming scope for its child components. So it always add prefix to his children id. So id of child component is:
parent_component_id".concat(":").concat("component_id")
. There is one pro tip that I had read in JavaServer Faces 2.0, The Complete Reference that even if you not add NamingContainer to your page it is always automatically added by JSF itself :) There also exist special algorith of this creation (Chapter 11: Building Custom UI Component -> Box called "Rules for Creating the Top-Level Component for a Composite Component"). Of course when you don't set id, it will be generate automatically (for example j_idt234). So full component id may look like this: "j_idt123:j_idt234:j_idt345".There is a way to override default component name separator (":"). You can define it in web.xml as context-param with name javax.faces.SEPARATOR_CHAR. For example:
To avoid adding scope to child component there is an attribute (only in UIForm component). But this is not recommended solution. Take a look for example at uiform-with-prependid-false-breaks-fajax-render
Component id usage (for example in "update", "process")
You can use whole id: "componentParent:component". This is not recommended (code will be fragile; any id changes will cause need to change ids in many places).
Inside one naming container you can use simple component id.
If you don't know this feature please take a look in PrimeFaces documentation. Prime Faces provide Search Expression Framework with couple of very usefull mechanism.
You can search by keywords.
Examples: @this (current component), @form (closest ancestor form), @namingcontainer (closest ancestor naming container), @parent, @widgetVar(name). You can also mixed those keywords in quite complex paths (Composite Expressions) for example: @form:@parent, @this:@parent:@parent
The second posibility PF gives you are PrimeFaces Selectors (PFS).
So you can for example:
update="@(form)"
update="@(.ui-datatable)"
update="@(.myStyle)"
Quite a powerful tool.
After having IntelliJ scan all my JARs for implementations of
javax.faces.component.NamingContainer
here is what I found:From PrimeFaces 5.3
From MyFaces 2.1