Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to prefix form id with colon

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

When the image is clicked, the images from the other datatable will be updated.

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

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

like image 959
Seitaridis Avatar asked Sep 11 '12 10:09

Seitaridis


1 Answers

The : prefix will make it an absolute client ID and thus it will be searched relative to the UIViewRoot instead of the closest parent NamingContainer. You should (must) use it when you want to refer a component which is not inside the same closest parent NamingContainer. The <h:form> and <h:dataTable> (and <p:dataTable>) are NamingContainer components.

See also How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar" for a detailed explaination.

like image 157
BalusC Avatar answered Oct 10 '22 02:10

BalusC