Skip to content

Commit

Permalink
https://github.com/eclipse-ee4j/mojarra/issues/5032
Browse files Browse the repository at this point in the history
Backport for 2.3
  • Loading branch information
BalusC committed Jan 13, 2022
1 parent 3f513b3 commit 02cb1ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
*<b>AjaxBehaviorRenderer</b> renders Ajax behavior for a component.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {

Expand Down

0 comments on commit 02cb1ee

Please sign in to comment.