faces icon indicating copy to clipboard operation
faces copied to clipboard

Fix behavior attachment for composites / provide a API

Open tandraschko opened this issue 5 years ago • 5 comments

There is no API in the JSF specs which allows to register a custom behavior correctly to a composite. (almost) every component lib had a hack for this, like you can see: https://github.com/primefaces/primefaces/blob/master/src/main/java/org/primefaces/behavior/base/AbstractBehaviorHandler.java (addAttachedObjectHandlerToMojarra / MyFaces)

tandraschko avatar Apr 19 '20 12:04 tandraschko

Trying to understand this. Can you provide a test case / code snippet? How exactly is <cc:clientBehavior> insufficient?

BalusC avatar Mar 01 '25 20:03 BalusC

Cant remember exactly, it has been years since working on this but the code is required, so that attaching p:ajax to a composite works correctly:

https://github.com/primefaces/primefaces/blob/master/primefaces/src/main/java/org/primefaces/behavior/base/AbstractBehaviorHandler.java#L135

also the docs here https://github.com/apache/myfaces/blob/a53561e8c2b07b6d8dcd2a7dfee6a4ea0b67a470/impl/src/main/java/org/apache/myfaces/view/facelets/tag/faces/core/AjaxHandler.java#L208

or see "jakarta.faces.view.AttachedObjectHandlers" in Mojarra

tandraschko avatar Mar 02 '25 12:03 tandraschko

Wait .. there's this comment in MyFaces AjaxHandler

// In RI, there exists a tag called composite:clientBehavior,
// but does not appear on spec or javadoc, maybe because this could be
// understand as an implementation detail, after all there exists a key
// called AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY that could be
// used to create a tag outside jsf implementation to attach targets.

This is what I meant with <cc:clientBehavior>. Is this comment saying that MyFaces doesn't have a <cc:clientBehavior>? Where did it go wrong? I scanned the 2.0 spec and it indeed doesn't have references to cc:clientBehavior/composite:clientBehavior (still not in 4.0 spec) but it did exist in tag/vdl documentation (2.0 is not anymore online, but here's 2.2 and here's 4.0).

An usage example can be found here https://stackoverflow.com/q/31912815

BalusC avatar Mar 02 '25 12:03 BalusC

yeah, i know it, just not sure about the relation between cc:clientBehavior and this code in PF.

maybe the code seen in PF is the bridge between cc:clientBehavior and f:/p:ajax? So that cc:clientBehavior uses the "AttachedObjectHandlers"?

tandraschko avatar Mar 02 '25 12:03 tandraschko

Ah right, it's ultimately in order to support a custom ajax behavior tag such as <p:ajax> to be understood by <cc:clientBehavior>. Gotcha, this is indeed missing in Faces API.

BalusC avatar Mar 02 '25 15:03 BalusC