Based on JSF specification section 3.1.6 and Portlet Specification section 12.3.4, MyFaces implementation (UIViewRoot and UIComponentBase) do not provide unique client id's.
In the current implementation(s) (1.1.1 & 1.1.2)
UIViewRoot.createUniqueId() is implemented as follows:
/* Provides a unique id for this component instance.
public String createUniqueId()
ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
return extCtx.encodeNamespace(UNIQUE_ID_PREFIX + _uniqueIdCounter++);
This makes the id unique for a component, but while rendering the clientId is used.
With this the namespace is repeated for every component.
if the jsp is as follows:
the id of the form in the markup will be portlet1_id0
and the id of the inputtext will be portlet1_id0:portlet1_id1.
The namespace is unecesarily repeated.
The above implementation will not make the id, in the generated markup unique if the id is specified in the jsp.
<h:inputtext id="name" .../>
the id of the form in the markup will be Myform
and the id of the inputtext will be Myform:name.
This does not make them unique in portal environment because createUniqueId is never called.
My opinion is that the fix should be in UIComponentBase.getClientId() not in UIViewRoot.createUniqueId().
getClientId() must return the namespace encoded client id.
the id's would be portlet1_id0 and portlet1_id0:_id1
the id's would be portlet1_Myform and portlet1_Myform:name.
I would appreciate comments on this from MyFaces developers.