When the id form prefix with colon

I have two data types in two forms: forma and formg. Inside each form there is p:dataTable , groupsa and groupsg. Each datatable has a custom column that displays an image ( h:graphicImage ) called fava and favg.

Clicking on the image will update the images from another file date.

 <p:ajax event="click" listener="#{agent.toogleFavorite}" update="fava, :formg:groupsg:favg" /> 

Without a colon, I get an exception:

 javax.faces.FacesException: Cannot find component with identifier "forma:agentsa:fava" referenced from "groupsg:0:favg". 

What is the difference between formg: groupsg: favg and: formg: groupsg: favg?

I am using JSF2.0 and PrimeFaces 3.4.

+4
source share
2 answers

Prefix : will make it the absolute identifier of the client and, therefore, it will search in relation to the UIViewRoot instead of the nearest parent of NamingContainer . You must (must) use it if you want to pass a component that is not inside the same nearest parent of NamingContainer . <h:form> and <h:dataTable> (and <p:dataTable> ) are components of the NamingContainer .

See also How do I know the client ID for ajax update / rendering? Cannot find component with expression "foo". link to the "bar" for a detailed explanation.

+9
source

Use a colon at the beginning when you want to find the identifier from the root of the page. This is necessary if the component that causes the update is not inside the same NamingContainer component that is being updated.

Do not use it if you want to search for the same NamingContainer. This can be done when both components (the one who caused the update and updateable) are inside the same NamingContainer.

By the way, "NamingContainers" are all components that add their identifier to their child components, for example, <h:form> , <p:dataTable> , <p:accordionPanel> , etc. Just look at the generated HTML to find out by adding its identifier to its children.

+5
source

Source: https://habr.com/ru/post/1433559/


All Articles