问题
I have a simple composite component, which is nested in some form etc. I would like to bind the click
event for all radio buttons in the <h:selectOneRadio>
of this composite component. I am trying to bind this event by name
property of inputs which will be created after <h:selectOneRadio id>
. Unfortunetly it is nested, so this code doesn't work, because the generated radio button ID is like:
"form:someid:someid:someid etc ect."
Composite component code:
<cc:implementation>
<..some forms etc.>
<h:selectOneRadio id="#{cc.attrs.id}" value="#{cc.attrs.value}">
<cc:insertChildren/>
</h:selectOneRadio>
</..some forms etc.>
<script type="text/javascript">
/* <![CDATA[ */
$('input[name=#{cc.attrs.id}]').click(function() {
console.log("click");
});
/* ]]> */
</script>
</cc:implementation>
Client code:
<mycomps:radio id="testID" ... >
<f:selectItem itemLabel="test" itemValue="false"/>
<f:selectItem itemLabel="test2" itemValue="true"/>
</mycomps:radio>
来源:https://stackoverflow.com/questions/21302781/javascript-composite-component-nested-forms