From 62c37d200d6c8d5c5aa0748735dbee7ca8986431 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Wed, 14 Apr 2021 09:45:34 -0400 Subject: [PATCH] Implement improved behavior of f;ajax render=@this in composites https://github.com/eclipse-ee4j/faces-api/issues/1567 --- .../html_basic/AjaxBehaviorRenderer.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) 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 71a29038bc..681629be93 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 @@ -16,6 +16,8 @@ package com.sun.faces.renderkit.html_basic; +import static jakarta.faces.component.UINamingContainer.getSeparatorChar; + import java.util.Collection; import java.util.Collections; import java.util.EnumSet; @@ -291,8 +293,13 @@ private static void appendIds(FacesContext facesContext, UIComponent component, boolean first = true; + UIComponent composite = UIComponent.getCompositeComponentParent(component); + String separatorChar = String.valueOf(getSeparatorChar(facesContext)); + for (String id : ids) { - if (id.trim().length() == 0) { + String expression = id.trim(); + + if (expression.length() == 0) { continue; } if (!first) { @@ -301,8 +308,17 @@ private static void appendIds(FacesContext facesContext, UIComponent component, first = false; } - if (id.equals("@all") || id.equals("@none") || id.equals("@form") || id.equals("@this")) { - builder.append(id); + if (composite != null) { + if (expression.startsWith("@this")) { + expression = expression.replaceFirst("@this", separatorChar + composite.getClientId(facesContext)); + } + else if (composite.getParent() != null && !expression.startsWith(separatorChar)) { + expression = composite.getParent().getClientId(facesContext) + separatorChar + expression; + } + } + + if (expression.equals("@all") || expression.equals("@none") || expression.equals("@form") || expression.equals("@this")) { + builder.append(expression); } else { if (searchExpressionContext == null) { searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(facesContext, component, EXPRESSION_HINTS, null); @@ -312,9 +328,9 @@ private static void appendIds(FacesContext facesContext, UIComponent component, } String resolvedClientId = null; try { - resolvedClientId = handler.resolveClientId(searchExpressionContext, id); + resolvedClientId = handler.resolveClientId(searchExpressionContext, expression); } catch (ComponentNotFoundException cnfe) { - resolvedClientId = getResolvedId(component, id); + resolvedClientId = getResolvedId(component, expression); } builder.append(resolvedClientId); }