[
https://issues.apache.org/jira/browse/MYFACES-3515?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13240949#comment-13240949
]
Leonardo Uribe commented on MYFACES-3515:
-----------------------------------------
I was not able to reproduce the bug, but I can see the problem. The reason why
we haven't seen it is any call to UIViewRoot.createUniqueId() increase the
unique counter, so as soon as the view gets bigger and bigger, the different
between the unique counter in UIViewRoot and other counters in composite
components gets bigger too. In few words, the probability to see the problem is
very small, but I'm glad someone has been able to see it.
The panel created by ComponentSupport.createFacetUIPanel is special. To be
restored properly and do not create duplicate ids or any other unwanted
conflicts, it requires an unique id. This code is usually called when more than
one component is added to a facet and it is necessary to create a shared
container. Use FaceletCompositionContext.generateUniqueComponentId() is not
possible, because <c:if> blocks inside a facet will make component ids
unstable. Use UniqueIdVendor is feasible but also will be affected by <c:if>
blocks inside a facet. The only solution that will generate real unique ids is
use the parent id and the facet name and derive an unique id that cannot be
generated by SectionUniqueIdCounter, doing the same trick as with metadata: use
a double __ and add a prefix (f). Note this id will never be printed into the
response, because this is just a container.
Note in facelets 1.1.x facets requires a container component, but in JSF 2.0 /
2.1, the behavior to handle facets was changed in order to make f:metadata
component work (requires facets can contain more than one component
automatically).
I also have notice a small performance improvement: our calls to
UniqueIdVendor.createUniqueId() increase the unique counter in 1, but when a
seed is passed this is not necessary. That will save one HashMap.get() call per
component create by facelets.
> Duplicate id using a facet in a composite component
> ---------------------------------------------------
>
> Key: MYFACES-3515
> URL: https://issues.apache.org/jira/browse/MYFACES-3515
> Project: MyFaces Core
> Issue Type: Bug
> Environment: MyFaces 2.1.6, Tomahawk20 1.1.11
> Reporter: dennis hoersch
> Attachments: duplicateIdTest.zip
>
>
> Hello,
> I get an IllegalStateException using a facet in a composite component. The
> facet gets the same id as the internal 'composite component'-facet. The facet
> is created using CumponentSupport.addFacet(). Here the id of the facet is
> generated using the view root instead of the UniqueIdVendor of the parent to
> whom the facet is added.
> In other places the id is retrieved with something like
> FaceletCompositionContext mctx =
> FaceletCompositionContext.getCurrentInstance(facesContext);
> UniqueIdVendor uniqueIdVendor = mctx.getUniqueIdVendorFromStack();
> if (uniqueIdVendor == null)
> {
> uniqueIdVendor = facesContext.getViewRoot();
> }
> String uid = uniqueIdVendor.createUniqueId(facesContext, null);
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira