@@ -426,7 +426,8 @@ private static void renderValueChangeEventListener(FacesContext context, UICompo
426426 ? Collections .singletonList (new ClientBehaviorContext .Parameter ("incExec" , true ))
427427 : Collections .emptyList ();
428428
429- addBehaviorEventListener (context , component , clientId , params , handlerName , userHandler , behaviorEventName , domEventName , null , false , incExec , true );
429+ addBehaviorEventListener (context , component , clientId , params , handlerName , userHandler , behaviorEventName , domEventName , null , false , incExec ,
430+ ResourceHandlerImpl .resolveCurrentNonce (context ) != null , true );
430431 }
431432
432433 // Renders the onclick event listener for command buttons. Handles
@@ -452,7 +453,8 @@ public static void renderOnclickEventListener(FacesContext context, UIComponent
452453 }
453454 }
454455
455- addBehaviorEventListener (context , component , null , params , handlerName , userHandler , behaviorEventName , domEventName , submitTarget , needsSubmit , false , true );
456+ addBehaviorEventListener (context , component , null , params , handlerName , userHandler , behaviorEventName , domEventName , submitTarget , needsSubmit , false ,
457+ ResourceHandlerImpl .resolveCurrentNonce (context ) != null , true );
456458
457459 }
458460
@@ -657,7 +659,8 @@ private static void renderPassThruAttributesOptimized(FacesContext context, Resp
657659 Attribute attr = knownAttributes [index ];
658660
659661 if (isBehaviorEventAttribute (attr , behaviorEventName )) {
660- addBehaviorEventListener (context , component , null , null , name , value , behaviorEventName , behaviorEventName , null , false , false , false );
662+ addBehaviorEventListener (context , component , null , null , name , value , behaviorEventName , behaviorEventName , null , false , false ,
663+ ResourceHandlerImpl .resolveCurrentNonce (context ) != null , false );
661664
662665 renderedBehavior = true ;
663666 } else {
@@ -669,7 +672,8 @@ else if (isBehaviorEventAttribute(name)) {
669672 Object value = attrMap .get (name );
670673 if (value != null && shouldRenderAttribute (value )) {
671674 if (name .substring (2 ).equals (behaviorEventName )) {
672- addBehaviorEventListener (context , component , null , null , name , value , behaviorEventName , behaviorEventName , null , false , false , false );
675+ addBehaviorEventListener (context , component , null , null , name , value , behaviorEventName , behaviorEventName , null , false , false ,
676+ ResourceHandlerImpl .resolveCurrentNonce (context ) != null , false );
673677
674678 renderedBehavior = true ;
675679 } else {
@@ -700,7 +704,8 @@ else if (isBehaviorEventAttribute(name)) {
700704 String attrName = attribute .getName ();
701705 String [] events = attribute .getEvents ();
702706 if (events != null && events .length > 0 && behaviorEventName .equals (events [0 ])) {
703- addBehaviorEventListener (context , component , null , null , attrName , null , behaviorEventName , behaviorEventName , null , false , false , false );
707+ addBehaviorEventListener (context , component , null , null , attrName , null , behaviorEventName , behaviorEventName , null , false , false ,
708+ ResourceHandlerImpl .resolveCurrentNonce (context ) != null , false );
704709 return ;
705710 }
706711 }
@@ -762,7 +767,8 @@ private static void renderPassthruAttribute(FacesContext context, ResponseWriter
762767 // If we've got a behavior for this attribute,
763768 // we may need to chain scripts together, so use
764769 // renderEventListener().
765- addBehaviorEventListener (context , component , null , null , attrName , value , eventName , eventName , null , false , false , false );
770+ addBehaviorEventListener (context , component , null , null , attrName , value , eventName , eventName , null , false , false ,
771+ ResourceHandlerImpl .resolveCurrentNonce (context ) != null , false );
766772 }
767773 }
768774
@@ -1672,7 +1678,8 @@ private static boolean isSubmitting(ClientBehavior behavior) {
16721678 * render the submit script to make the link submit.
16731679 */
16741680 private static void addBehaviorEventListener (FacesContext context , UIComponent component , String clientId , Collection <ClientBehaviorContext .Parameter > params , String handlerName ,
1675- Object handlerValue , String behaviorEventName , String domEventName , String submitTarget , boolean needsSubmit , boolean includeExec , boolean flushPendingBehaviorEventListeners ) throws IOException {
1681+ Object handlerValue , String behaviorEventName , String domEventName , String submitTarget , boolean needsSubmit , boolean includeExec ,
1682+ boolean renderAsEventListener , boolean flushPendingBehaviorEventListeners ) throws IOException {
16761683
16771684 String userHandler = getNonEmptyUserHandler (handlerValue );
16781685 List <ClientBehavior > behaviors = getClientBehaviors (component , behaviorEventName );
@@ -1706,6 +1713,13 @@ private static void addBehaviorEventListener(FacesContext context, UIComponent c
17061713 assert false ;
17071714 }
17081715
1716+ if (!renderAsEventListener ) {
1717+ if (handler != null ) {
1718+ context .getResponseWriter ().writeAttribute (handlerName , handler , null );
1719+ }
1720+ return ;
1721+ }
1722+
17091723 if (flushPendingBehaviorEventListeners ) {
17101724 flushPendingBehaviorEventListeners (context , component , clientId );
17111725 }
0 commit comments