Skip to content

Commit

Permalink
Also fix AjaxBehaviors (the case when <f:ajax> wraps components)
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Sep 30, 2023
1 parent 3bf2287 commit 0ba351d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

package com.sun.faces.component.behavior;

import static com.sun.faces.renderkit.RenderKitUtils.isHtml5BehaviorAttribute;
import static com.sun.faces.renderkit.RenderKitUtils.isOutputHtml5Doctype;

import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.sun.faces.renderkit.RenderKitUtils;

import jakarta.faces.application.Application;
import jakarta.faces.component.behavior.AjaxBehavior;
import jakarta.faces.component.behavior.ClientBehavior;
Expand Down Expand Up @@ -136,7 +141,7 @@ public void addBehavior(FacesContext context, ClientBehaviorHolder behaviorHolde
}

// We only add the
if (shouldAddBehavior(behaviorHolder, myEventName)) {
if (shouldAddBehavior(context, behaviorHolder, myEventName)) {
ClientBehavior behavior = createBehavior(context);
behaviorHolder.addClientBehavior(myEventName, behavior);
}
Expand All @@ -145,11 +150,11 @@ public void addBehavior(FacesContext context, ClientBehaviorHolder behaviorHolde

// Tests whether we should add an AjaxBehavior to the specified
// ClientBehaviorHolder/event name.
private boolean shouldAddBehavior(ClientBehaviorHolder behaviorHolder, String eventName) {
private boolean shouldAddBehavior(FacesContext context, ClientBehaviorHolder behaviorHolder, String eventName) {

// First need to make sure that this ClientBehaviorHolder
// supports the specified event type.
if (!behaviorHolder.getEventNames().contains(eventName)) {
if (!behaviorHolder.getEventNames().contains(eventName) || !(isOutputHtml5Doctype(context) && isHtml5BehaviorAttribute(eventName))) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ private static void renderPassThruAttributesOptimized(FacesContext context, Resp
}
}
}
else if (isHtml5 && isBehaviorAttribute(name)) {
else if (isHtml5 && isHtml5BehaviorAttribute(name)) {
Object value = attrMap.get(name);
if (value != null && shouldRenderAttribute(value)) {
if (name.substring(2).equals(behaviorEventName)) {
Expand All @@ -652,7 +652,7 @@ else if (isHtml5 && isBehaviorAttribute(name)) {
if (behaviorEventName != null && !renderedBehavior) {

if (isHtml5) {
List<String> behaviorAttributes = setAttributes.stream().filter(RenderKitUtils::isBehaviorAttribute).collect(toList());
List<String> behaviorAttributes = setAttributes.stream().filter(RenderKitUtils::isHtml5BehaviorAttribute).collect(toList());

for (String attrName : behaviorAttributes) {
String eventName = attrName.substring(2);
Expand Down Expand Up @@ -696,7 +696,7 @@ private static void renderPassThruAttributesUnoptimized(FacesContext context, Re
boolean isXhtml = !isHtml5 && RIConstants.XHTML_CONTENT_TYPE.equals(writer.getContentType());

Map<String, Object> attrMap = component.getAttributes();
List<String> behaviorAttributes = isHtml5 && setAttributes != null ? setAttributes.stream().filter(RenderKitUtils::isBehaviorAttribute).collect(toList()) : emptyList();
List<String> behaviorAttributes = isHtml5 && setAttributes != null ? setAttributes.stream().filter(RenderKitUtils::isHtml5BehaviorAttribute).collect(toList()) : emptyList();

for (Attribute attribute : knownAttributes) {
String attrName = attribute.getName();
Expand Down Expand Up @@ -730,7 +730,7 @@ private static void renderPassthruAttribute(FacesContext context, ResponseWriter
}
}

private static boolean isBehaviorAttribute(String name) {
public static boolean isHtml5BehaviorAttribute(String name) {
return name.startsWith("on") && name.length() > 2;
}

Expand Down

0 comments on commit 0ba351d

Please sign in to comment.