[
https://issues.apache.org/jira/browse/ADFFACES-41?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Matthias Weßendorf updated ADFFACES-41:
---------------------------------------
Fix Version/s: 1.0.0-incubating-core
Affects Version/s: 1.0.0-incubating-core
> Children out of order in ChildArrayList when re-added to different parent
> -------------------------------------------------------------------------
>
> Key: ADFFACES-41
> URL: https://issues.apache.org/jira/browse/ADFFACES-41
> Project: MyFaces ADF-Faces
> Issue Type: Bug
> Affects Versions: 1.0.0-incubating-core
> Environment: All
> Reporter: John Fan
> Assigned To: Adam Winer
> Priority: Minor
> Fix For: 1.0.0-incubating-core
>
> Attachments: trunk.patch
>
>
> Here is the code in the add(int index, Object element) method in
> org.apache.myfaces.adf.component.ChildArrayList class:
>
> if (child.getParent() != null)
> {
> index = __removeFromParent(child, index);
> }
> child.setParent(_parent);
> super.add(index, child);
>
> What it is trying to do is to add a new child (the child variable in the
> code) to this ChildArrayList, and automatically detach the new child from its
> old parent, if exists, by calling __removeFromParent.
>
> If you look into the __removeFromParent() method, you can find out that this
> chunk of code assumes that the old parent is identical to the new parent it
> is being added under, and __removeFromParent returns an adjusted index value
> according to this assumption. This assumption is not always right and this is
> causing problems.
> One way of fixing this is:
> Object oldParent = child.getParent();
> if (oldParent != null)
> {
> int adjustedIndex = __removeFromParent(child, index);
> //Only adjust the index when the child is re-added to the same parent
> if (oldParent == _parent)
> {
> index = adjustedIndex;
> }
> }
> child.setParent(_parent);
> super.add(index, child);
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.