private static void addChild(UIComponent parent, String prevId, UIComponent child) { if (parent != null) { List<UIComponent> children = parent.getChildren(); int size = children.size(); boolean hasPrev = prevId == null; int i = 0; for (; i < size; i++) { UIComponent oldChild = children.get(i); if (hasPrev && oldChild.getId() != null) { children.add(i, child); return; } else if (prevId != null && prevId.equals(oldChild.getId())) hasPrev = true; } parent.getChildren().add(child); } }