I want, on server side, to add a javascript function to a h:form, so it can later be called on client side.
I use
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite">
and have tried "onload", like this
<h:form onload="this.myfunc=function(){alert('Hello world');}" ...
But per documentation, there is no "onload" for h:form.
The purpose is to have a composite that contains the h:form, and a page that uses this composite and contains some javascript code to prepare and trigger an ajax-call on the composite. The page should only call myfunc and should not need to know what the composite does with the call, so the composite may change without any need to change the page.
Edit: the composite looks something like
<composite:interface>
<composite:attribute name="imgId" required="true" />
<composite:attribute name="flav" default="r" />
<composite:attribute name="width" default="472" />
</composite:interface>
<composite:implementation>
<h:form id="${cc.attrs.imgId}" styleClass="small">
<f:event type="postAddToView" listener="#{mBean.register}" />
<f:attribute name="myId" value="hmta${cc.attrs.imgId}" />
<h:graphicImage width="${cc.attrs.width}" id="${cc.attrs.imgId}"
onclick="this.nextSibling.value=mods(event)" onmouseover="aa=this.id"
value="images/img?#{cc.attrs.flav}=#{Math.random()}">
<f:ajax event="click" execute="@this k"
listener="#{mBean.handleEvent}" render="@this">
</f:ajax>
</h:graphicImage>
<h:inputHidden id="k" value="#{mBean.keyX}" />
</h:form>
</composite:implementation>
Edit2: the composite would typically be used more than once per page.