Naming Container in JSF2/PrimeFaces [duplicate]

What are the possible naming container in Prime faces

In JSF naming containers derive from UINamingContainer.

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”

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):

Set the component identifier of this UIComponent (if any). Component identifiers must obey the following syntax restrictions:
Must not be a zero-length String.
First character must be a letter or an underscore (‘‘).
Subsequent characters must be a letter, a digit, an underscore (‘
‘), or a dash (‘-‘).

.. furthermore, important for you:

The specified identifier must be unique among all the components (including facets) that are descendents of the nearest ancestor UIComponent that is a NamingContainer, or within the scope of the entire component tree if there is no such ancestor that is a NamingContainer.

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:

<h:outputText value="test1" id="userNameTextbox" />
<h:form id="container1">
  <h:outputText value="test2" id="userNameTextbox" />
</h:form>
<h:form id="container2">
  <h:outputText value="test3" id="userNameTextbox" />
</h:form>

.. 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

Leave a Comment