wffweb/src/main/java/com/webfirmframework/wffweb/tag/html/AbstractHtml.java
private boolean insertBefore(final AbstractHtml[] removedParentChildren,
            final AbstractHtml[] abstractHtmls) {

        final int parentChildrenSize = parent.children.size();
        if (parentChildrenSize > 0) {

            final InsertBeforeListener insertBeforeListener = sharedObject
                    .getInsertBeforeListener(ACCESS_OBJECT);

            parent.children.clear();

            final InsertBeforeListener.Event[] events = new InsertBeforeListener.Event[abstractHtmls.length];

            int count = 0;

            for (final AbstractHtml parentChild : removedParentChildren) {

                if (equals(parentChild)) {

                    for (final AbstractHtml abstractHtmlToInsert : abstractHtmls) {

                        final boolean alreadyHasParent = abstractHtmlToInsert.parent != null;

                        if (insertBeforeListener != null) {
                            AbstractHtml previousParent = null;
                            if (abstractHtmlToInsert.parent != null
                                    && abstractHtmlToInsert.parent.sharedObject == sharedObject) {
                                previousParent = abstractHtmlToInsert.parent;
                            }
                            final InsertBeforeListener.Event event = new InsertBeforeListener.Event(
                                    parent, abstractHtmlToInsert, this,
                                    previousParent);
                            events[count] = event;
                            count++;
                        }

                        // if alreadyHasParent = true then it means the
                        // child is
                        // moving from one tag to another.

                        if (alreadyHasParent) {
                            abstractHtmlToInsert.parent.children
                                    .remove(abstractHtmlToInsert);
                        }

                        initSharedObject(abstractHtmlToInsert);

                        abstractHtmlToInsert.parent = parent;

                        parent.children.add(abstractHtmlToInsert);
                    }

                }

                parent.children.add(parentChild);
            }

            if (insertBeforeListener != null) {
                insertBeforeListener.insertedBefore(events);
            }

            return true;

        }
        return false;
    }
private boolean insertBefore(final AbstractHtml[] removedParentChildren,
            final AbstractHtml[] abstractHtmls) {

        final int parentChildrenSize = parent.children.size();
        if (parentChildrenSize > 0) {

            final InsertBeforeListener insertBeforeListener = sharedObject
                    .getInsertBeforeListener(ACCESS_OBJECT);

            parent.children.clear();

            final InsertBeforeListener.Event[] events = new InsertBeforeListener.Event[abstractHtmls.length];

            int count = 0;

            for (final AbstractHtml parentChild : removedParentChildren) {

                if (equals(parentChild)) {

                    for (final AbstractHtml abstractHtmlToInsert : abstractHtmls) {

                        final boolean alreadyHasParent = abstractHtmlToInsert.parent != null;

                        if (insertBeforeListener != null) {
                            AbstractHtml previousParent = null;
                            if (abstractHtmlToInsert.parent != null
                                    && abstractHtmlToInsert.parent.sharedObject == sharedObject) {
                                previousParent = abstractHtmlToInsert.parent;
                            }
                            final InsertBeforeListener.Event event = new InsertBeforeListener.Event(
                                    parent, abstractHtmlToInsert, this,
                                    previousParent);
                            events[count] = event;
                            count++;
                        }

                        // if alreadyHasParent = true then it means the
                        // child is
                        // moving from one tag to another.

                        if (alreadyHasParent) {
                            abstractHtmlToInsert.parent.children
                                    .remove(abstractHtmlToInsert);
                        }

                        initSharedObject(abstractHtmlToInsert);

                        abstractHtmlToInsert.parent = parent;

                        parent.children.add(abstractHtmlToInsert);
                    }

                }

                parent.children.add(parentChild);
            }

            if (insertBeforeListener != null) {
                insertBeforeListener.insertedBefore(events);
            }

            return true;

        }
        return false;
    }
should be used inside a synchronized block. NB:- It's removing
removedParentChildren by parent.children.clear(); in this method.

@param removedParentChildren
just pass the parent children, no need
to remove it from parent. It's removing
by parent.children.clear();
@param abstractHtmls
@return true if inserted otherwise false.
@since 2.1.6
@author WFF