diff --git a/impl/src/main/java/com/sun/faces/facelets/tag/composite/InsertChildrenHandler.java b/impl/src/main/java/com/sun/faces/facelets/tag/composite/InsertChildrenHandler.java index 7b8d1ca08a..3cabe6acc3 100644 --- a/impl/src/main/java/com/sun/faces/facelets/tag/composite/InsertChildrenHandler.java +++ b/impl/src/main/java/com/sun/faces/facelets/tag/composite/InsertChildrenHandler.java @@ -45,6 +45,8 @@ public class InsertChildrenHandler extends TagHandlerImpl { private final Logger LOGGER = FacesLogger.TAGLIB.getLogger(); private static final String REQUIRED_ATTRIBUTE = "required"; + public static final String INDEX_ATTRIBUTE = "InsertChildrenHandler.idx"; + // This attribute is not required. If not defined, then assume the facet // isn't necessary. private TagAttribute required; @@ -105,8 +107,8 @@ private class RelocateChildrenListener extends RelocateListener { this.ctx = ctx; this.component = component; - if (!component.getAttributes().containsKey("idx")) { - component.getAttributes().put("idx", idx); + if (!component.getAttributes().containsKey(INDEX_ATTRIBUTE)) { + component.getAttributes().put(INDEX_ATTRIBUTE, idx); // NOTE: this is also used by AjaxBehaviorRenderer in order to detect if f:ajax was handled by cc:insertChildren. See also #5032 } this.idx = idx; this.location = location; @@ -174,7 +176,7 @@ public void processEvent(ComponentSystemEvent event) // ----------------------------------------------------- Private Methods private int getIdx() { - Integer idx = (Integer) component.getAttributes().get("idx"); + Integer idx = (Integer) component.getAttributes().get(INDEX_ATTRIBUTE); return ((idx != null) ? idx : this.idx); } diff --git a/impl/src/main/java/com/sun/faces/renderkit/html_basic/AjaxBehaviorRenderer.java b/impl/src/main/java/com/sun/faces/renderkit/html_basic/AjaxBehaviorRenderer.java index 8d39cc26f8..92e0a96e0c 100644 --- a/impl/src/main/java/com/sun/faces/renderkit/html_basic/AjaxBehaviorRenderer.java +++ b/impl/src/main/java/com/sun/faces/renderkit/html_basic/AjaxBehaviorRenderer.java @@ -20,31 +20,32 @@ import java.util.Collection; import java.util.Collections; +import java.util.EnumSet; import java.util.LinkedList; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.faces.component.ActionSource; import javax.faces.component.EditableValueHolder; import javax.faces.component.UIComponent; +import javax.faces.component.UINamingContainer; import javax.faces.component.behavior.AjaxBehavior; import javax.faces.component.behavior.ClientBehavior; import javax.faces.component.behavior.ClientBehaviorContext; import javax.faces.component.html.HtmlCommandScript; +import javax.faces.component.search.ComponentNotFoundException; +import javax.faces.component.search.SearchExpressionContext; +import javax.faces.component.search.SearchExpressionHandler; +import javax.faces.component.search.SearchExpressionHint; import javax.faces.context.FacesContext; import javax.faces.event.AjaxBehaviorEvent; import javax.faces.event.PhaseId; import javax.faces.render.ClientBehaviorRenderer; +import com.sun.faces.facelets.tag.composite.InsertChildrenHandler; import com.sun.faces.renderkit.RenderKitUtils; import com.sun.faces.util.FacesLogger; -import java.util.EnumSet; -import java.util.Set; -import javax.faces.component.UINamingContainer; -import javax.faces.component.search.ComponentNotFoundException; -import javax.faces.component.search.SearchExpressionContext; -import javax.faces.component.search.SearchExpressionHandler; -import javax.faces.component.search.SearchExpressionHint; /* *AjaxBehaviorRenderer renders Ajax behavior for a component. @@ -334,7 +335,7 @@ private static void appendIds(FacesContext facesContext, boolean clientResolveableExpression = expression.equals("@all") || expression.equals("@none") || expression.equals("@form") || expression.equals("@this"); - if (composite != null && expression.equals("@this") || expression.startsWith("@this" + separatorChar)) { + if (composite != null && !isHandledByInsertChildren(component, composite) && (expression.equals("@this") || expression.startsWith("@this" + separatorChar))) { expression = expression.replaceFirst("@this", separatorChar + composite.getClientId(facesContext)); clientResolveableExpression = false; } @@ -371,6 +372,16 @@ private static void appendIds(FacesContext facesContext, builder.append("'"); } + private static boolean isHandledByInsertChildren(UIComponent component, UIComponent composite) { + for (UIComponent parent = component.getParent(); parent != null && !parent.equals(composite); parent = parent.getParent()) { + if (parent.getAttributes().containsKey(InsertChildrenHandler.INDEX_ATTRIBUTE)) { + return true; + } + } + + return false; + } + // Returns the resolved (client id) for a particular id. private static String getResolvedId(UIComponent component, String id) {