I have this code that works although I would expect it to fail. The component to receive focus is the <p:inputText> so I would expect its name to be custForm:panelGrid:name-id (to reflect the embedding of the <p:inputText> component within the <p:panelGrid> component). Yet the only naming that works is custForm:name-id. It appears that there are some PrimeFaces components which do not “insert” their id in the qualified name. If so, where is that documented?
<h:form id="custForm" styleClass="jsfcrud_list_form">
<script type="text/javascript">
function primeFacesId()
{
var original = 'custForm:name-id';
var idToSetFocus = PrimeFaces.escapeClientId(original);
$(idToSetFocus).focus();
}
</script>
<script>
jQuery(document).ready(function() {
primeFacesId();
});
</script>
<p:panelGrid columns="10" style="width: 98%;margin-left: 1%;margin-right: 1%;" id="panelGrid">
<h:outputLabel for="name" value="Name:" />
<p:inputText id="name-id" value="#{customerLController.nameDBConstraint}" label="name" />
(...)
[I am behind corporate firewall and due to the “SO requires external JavaScript from another domain” I won’t be able to accept any answers for a couple of days]
For plain JSF all components that implement the NamingContainer interface add their id as prefix to all components inside the container. This is for instance
h:formorh:dataTablebut noth:panelGrid. You can browse the API documentation for Mojarra to get detailed information on that.Since many Primefaces components are derived from standard JSF components, I think their behavior is similar.
UPDATE:
I found this in the Primefaces documentation for version 3.2:
At least for
p:panelGridthis is not true (and can be verified in the html source of the PF showcase for the panelgrid).