Skip to content

Commit

Permalink
Loop through children to check all ids before adding
Browse files Browse the repository at this point in the history
  • Loading branch information
volosied committed Oct 19, 2023
1 parent 50d6e0e commit 7adc5c1
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.myfaces.application.StateManagerImpl;
import org.apache.myfaces.application.viewstate.StateCacheUtils;
import org.apache.myfaces.context.RequestViewContext;
import org.apache.myfaces.core.api.shared.ComponentUtils;
import org.apache.myfaces.util.lang.ClassUtils;
import org.apache.myfaces.util.lang.HashMapUtils;
import org.apache.myfaces.component.visit.MyFacesVisitHints;
Expand Down Expand Up @@ -642,17 +643,25 @@ public void invokeContextCallback(FacesContext context, UIComponent target)
{
try
{
UIComponent parent = target;
UIComponent dup = parent.getChildren().get(childIndex);
if (child.getId().equals(dup.getId())) // avoid DuplicateIdException - myfaces-4623
{
parent.getChildren().remove(childIndex.intValue());
parent.getChildren().add(childIndex, child);
}
else
{
target.getChildren().add(childIndex, child);
}
UIComponent parent = target;
for (int i = 0, childCount = parent.getChildCount(); i < childCount; i ++)
{
UIComponent dup = parent.getChildren().get(i);
// myfaces-4623: avoid duplicate id exceptions w/ c:forEach for Resource Dependencies
if (child.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX + ComponentUtils.RD_ID_PREFIX)
&& child.getId().equals(dup.getId()))
{
// Replace
parent.getChildren().remove(i);
parent.getChildren().add(i, child);
done = true;
break;
}
}
if(!done) // if not replaced yet, then just add it.
{
target.getChildren().add(childIndex, child);
}
}
catch (IndexOutOfBoundsException e)
{
Expand Down

0 comments on commit 7adc5c1

Please sign in to comment.