Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Container in JSF2/PrimeFaces [duplicate]

Tags:

jsf

primefaces

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"?

like image 206
Waqas Ahmed Avatar asked Nov 24 '12 17:11

Waqas Ahmed


2 Answers

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

like image 82
Manuel Avatar answered Oct 02 '22 03:10

Manuel


After having IntelliJ scan all my JARs for implementations of javax.faces.component.NamingContainer here is what I found:

From PrimeFaces 5.3

  • AccordionPanel
  • Carousel
  • Columns
  • DataGrid
  • DataList
  • DataScroller
  • DataTable
  • Page
  • Ring
  • SubTable
  • Subview
  • TabView
  • TreeTable
  • UIData
  • UITabPanel

From MyFaces 2.1

  • HtmlDataTable
  • HtmlForm
  • UITree
  • UIForm
like image 35
Matt Stephenson Avatar answered Oct 02 '22 03:10

Matt Stephenson